Grouping and Joining

Slightly more complex query functionality exists in the family of grouping and joining operators. The number of overloads for those standard query operators may be frightening at first, so let’s take a closer look.


To put elements in buckets with similar properties, grouping operations are used. No fewer than eight overloads exist for the GroupBy operator, which by themselves can be grouped into some categories. One set of overloads exposes a sequence containing IGrouping<TKey, TElement> objects, which contain the grouping key and the elements that go with it (because each grouping object is also an IEnumerable):

public interface IGrouping<out TKey, out TElement> : IEnumerable<TElement> ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.