In LINQ, grouping operators pick the elements of the sequence or collection which contains common attributes and serve them in a group. Or in other words, we can say that the grouping operator returns the group of elements based on the given key. This group is held in a special type of collection, which implements the IGrouping<TKey, TElement> interface, where TKey is the key through which the group is created and TElement is the collection of elements which peers with the grouping key value. For example, a sequence contains 6 elements, i.e, Abc, cvd, Abc, Abc, ert, Por, now we want a group in which contain all the Abc present in that sequence. So Abc is the key through which we create another group that contains 3 Abc. As shown in the below image:
The Standard Query Operator contains two different types of grouping operators:
The ToLookup operator is used to put the element in a LookUp<TKey, TElement> based on a key selector function. Here, LookUp<TKey, TElement> is a one-to-many dictionary. The working of the ToLookup operator is quite similar to the GroupBy operator.
- It does not support query syntax in C# and VB.Net languages.
- It support method syntax in both C# and VB.Net languages.
- It only present in Enumerable class.
- It is overloaded in four different types.
- It throw ArgumentNullException if the source or keySelector is null.
- It is implemented by using immediate execution.
Group By Gender: Female Employee Name: Anjita Employee Name: Soniya Employee Name: Supriya Employee Name: Anju Group By Gender: Male Employee Name: Rohit Employee Name: Anil
- LINQ | Grouping Operator | GroupBy
- LINQ | Set Operator | Except
- LINQ | Quantifier Operator | Any
- LINQ | Quantifier Operator | Contains
- LINQ | Set Operator | Union
- LINQ | Quantifier Operator | All
- LINQ | Set Operator | Intersect
- LINQ | Element Operator | Last
- LINQ | Partition Operator | Take
- LINQ | Set Operator | Distinct
- LINQ | Filtering Operator | where
- LINQ | Element Operator | First
- LINQ | Concatenation Operator | Concat
- LINQ | Element Operator | FirstOrDefault
- LINQ | Partition Operator | TakeWhile
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.