Hooked on LINQ

Hooked on LINQ - Developers' Wiki
for .NET Language Integrated Query

Quick Search

Advanced Search »

LongCount Operator

Modified: 2007/01/17 05:34 by t_magennis - Categorized as: LINQ to Objects
{TOC}
Namespace:System.Linq
Assembly:System.Core.dll
Extends:IEnumerable<T>

Back to Standard Query Operator Index


Edit

Introduction

The LongCount operator counts the number of elements in a sequence with a return type of Long.

Edit

Method 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)



Edit

Exceptions

Throws an ArgumentNullException if source or predicate is null.

Edit

Pseudocode

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.

Edit

Loop Count

1. The entire sequence is iterated once to evaluate the count result.

Edit

Code Samples

TODO: Needs code sample.

If you would like to comment on this page, click on the Discuss button located on the top-right of each page. Feel free to edit any mistakes or ommissions you find. If you have an objection or find in-appropriate content then contact the administrator. This website is not affiliated with Microsoft®, all content and opinions are those of the specific author and some advice, solutions and article may contain un-intentional errors - please use care. Powered by ScrewTurn Wiki version 2.0.33. Some of the icons created by FamFamFam.