{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
The Any operator checks whether any element of a sequence satisfies a condition.
EditMethod Signatures
// 1 - If any elements exist in the sequence
public static bool Any<TSource>(
this IEnumerable<TSource> source)
// 2 - If any elements in the sequence satisfy a predicate function.
public static bool Any<TSource>(
this IEnumerable<TSource> source,
Func<TSource, bool> predicate)EditExceptions
Throws an ArgumentNullException is
source or
predicate is null.
EditPseudo-code
Overload 1
If
source is null, throw an ArgumentNullException.
If there is at least one element in the
source sequence, return true; Otherwise return false.
Overload 2
If
source is null, throw an ArgumentNullException.
If
predicate is null, throw an ArgumentNullException.
Iterate the
source sequence
If predicate( this element ) is true, return true immediately.
Return false only if all elements failed the predicate function (i.e. we fell through the loop).
EditLoop Count
Overload 1: < 1. Always only looks at only one element.
Overload 2: < 1 if the predicate passes on any element, otherwise 1.
EditCode Samples
TODO:Needs code sample.