KeepUpToN
Filters a collection keeping up to n occurences of each value.
- Use
IEnumerable.Distinct()in combination withIEnumerable.ToDictionary()to create a dictionary with an initial count of0for each distinct value indata. - Use
IEnumerable.Where()to filter out occurences after thenth one for each element, using the previously created dictionary.