LINQ GroupBy() MethodIn LINQ, the GroupBy operator is used to groupin the list/collection items based on the specified value of the key, and it returns a collection of IGrouping<key, Values>. The GroupBy method in LINQ is the same as the SQL group by statement. Syntax of LINQ GroupBy() MethodHere is the syntax of using the LINQ GroupBy() method to group the elements based on the specified value of the key. From the above syntax, we are grouping the "objStudent" items of the collection based on the student location. Example of LINQ GroupBy() in Method SyntaxHere is the example of using the LINQ GroupBy() in method syntax. In the above example, we are grouping the collection of items in "objStudent" based on the location of the student. Output: Example of LINQ GroupBy() in Query SyntaxHere is the example of using the LINQ GroupBy() operator. Output:
Next TopicLINQ Join Operators
|