{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
The LongCount operator counts the number of elements in a sequence with a return type of Long.
EditMethod Signatures
// 1 - Count the number of elements in the source sequence.
public static long LongCount<TSource>(
this IEnumerable<TSource> source)
// 2 - Count the number of elements that pass the predicate function.
public static long LongCount<TSource>(
this IEnumerable<TSource> source,
Func<TSource, bool> predicate)EditExceptions
Throws an ArgumentNullException if
source or
predicate is null.
EditPseudocode
Overload 1
If
source is null, throw ArgumentNullException.
Initialize count result as 0.
Iterate over the source sequence.
count result = previous count result value + 1.
Return the count result value.
Overload 2
If
source is null, throw ArgumentNullException.
If
predicate is null, throw an ArgumentNullException.
Iterate the source sequence
If predicate (current element) returns true, count result = previous count result value + 1.
Return the count result value.
EditLoop Count
1. The entire sequence is iterated once to evaluate the count result.
EditCode Samples
TODO: Needs code sample.