Rediger

Del via


by (C# Reference)

Use the by contextual keyword in the group clause of a query expression to specify how to group the returned items. For more information, see group clause.

The C# language reference documents the most recently released version of the C# language. It also contains initial documentation for features in public previews for the upcoming language release.

The documentation identifies any feature first introduced in the last three versions of the language or in current public previews.

Tip

To find when a feature was first introduced in C#, consult the article on the C# language version history.

The following example shows how to use the by contextual keyword in a group clause to group students by the first letter of each student's last name.

var query = from student in students
            group student by student.LastName[0];

See also