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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.