CountBy
Applies a key-generating function to each element of a collection and returns a collection yielding unique keys and their number of occurrences in the original collection.
Parameters
Returns
Func<T, TKey> projection
IEnumerable<T> source
IEnumerable<(TKey Key, int Count)>
Usage
The projection
functions is used to creates a key to each element, after that, this method returns the number of occurrences of this key in original collection.
Counting even and odd numbers in a collection
Counting products by a price range
Last updated
Was this helpful?