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
- LINQ | How to find aggregate of the given sequence?
- LINQ | Let Keyword
- What is Query in LINQ?
- LINQ | Set Operator | Except
- LINQ | Element Operator | Last
- LINQ | Method Syntax
- LINQ | Query Syntax
- LINQ | How to find the sum of the given Sequence?
- LINQ | Element Operator | First
- LINQ | Filtering Operator | where
- LINQ | Quantifier Operator | All
- LINQ | Quantifier Operator | Contains
- LINQ | Set Operator | Intersect
- Aggregation Function in LINQ
- Cross Join in LINQ
- LINQ | Set Operator | Distinct
- LINQ | Quantifier Operator | Any
- LINQ | Set Operator | Union
- LINQ | Partition Operator | Take
- LINQ | Element Operator | Single
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.