Query Expression Syntax for Standard Query Operators (C#)

Some of the more frequently used standard query operators have dedicated C# language keyword syntax that enables them to be called as part of a query expression. A query expression is a different, more readable form of expressing a query than its method-based equivalent. Query expression clauses are translated into calls to the query methods at compile time.

Query Expression Syntax Table

The following table lists the standard query operators that have equivalent query expression clauses.

Method C# Query Expression Syntax
Cast Use an explicitly typed range variable, for example:

from int i in numbers

(For more information, see from clause.)
GroupBy group … by

-or-

group … by … into …

(For more information, see group clause.)
GroupJoin<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>, Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,IEnumerable<TInner>,TResult>) join … in … on … equals … into …

(For more information, see join clause.)
Join<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>, IEnumerable<TInner>, Func<TOuter,TKey>, Func<TInner,TKey>, Func<TOuter,TInner,TResult>) join … in … on … equals …

(For more information, see join clause.)
OrderBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) orderby

(For more information, see orderby clause.)
OrderByDescending<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) orderby … descending

(For more information, see orderby clause.)
Select select

(For more information, see select clause.)
SelectMany Multiple from clauses.

(For more information, see from clause.)
ThenBy<TSource,TKey>(IOrderedEnumerable<TSource>, Func<TSource,TKey>) orderby …, …

(For more information, see orderby clause.)
ThenByDescending<TSource,TKey>(IOrderedEnumerable<TSource>, Func<TSource,TKey>) orderby …, … descending

(For more information, see orderby clause.)
Where where

(For more information, see where clause.)

See also