Say you have the following sequence of strings:
You can use the Count() extension method of IEnumerable to get the number of elements in the array:
…which returns 26. Count has an overload where you can specify a lambda filter. The following function returns the number of string elements which consist of at least 5 characters:
…which returns 19.
IEnumerable has a LongCount method which has the same function and overloads as Count. It is used for collections whose size doesn’t fit into int.MaxValue and returns a long instead of an int. You can of course use it with small sequences as well but the returned value will be a long.
View the list of posts on LINQ here.