LINQ | Aggregate Operators | LongCount
In LINQ, a Count operator is available to count the elements of the given sequence or collection. But there is a drawback of count operator, i.e, it only works for the MaxValue, i.e, 2147483647, if you try to more than this value then it will throw an OverflowException. So this drawback is overcome in the LongCount operator. It allows you to count the elements present in the large collection or sequence, voluntary only those elements that satisfy the given predicate function. Or in other words, it returns an Int64 value that represents the number of elements in a sequence or collection. This method is overloaded in two different ways:
- LongCount<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>): This method is used to return an Int64 value that represents how many elements in a sequence satisfy the given condition.
- LongCount<TSource>(IEnumerable<TSource>): This method is used to return an Int64 value that represents the total number of elements present in the given sequence or collection.
- It does not support query syntax in C# and VB.Net languages.
- It can support method syntax in C# and VB.Net languages.
- It present in both the Queryable and Enumerable class.
- It will throw an ArgumentNullException, if the source or predicate is null.
- It will throw an OverflowException, if the number of matching elements exceeds MaxValue, i.e, 9223372036854775807.
How many employee present in the company: 6
My Personal Notes arrow_drop_up
Please Login to comment...