Javatpoint Logo
Javatpoint Logo

LINQ GroupBy() Method

In 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() Method

Here 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 Syntax

Here 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:

LINQ GroupBy() Method

Example of LINQ GroupBy() in Query Syntax

Here is the example of using the LINQ GroupBy() operator.

Output:

LINQ GroupBy() Method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA