标准查询运算符的查询表达式语法

某些使用更频繁的标准查询运算符具有专用的 C# 和 Visual Basic 语言关键字语法,利用这些语法,将可以在“查询表达式”中调用这些运算符。 与“基于方法”的查询表达形式相比,查询表达式是一种不同的、可读性更好的查询表达形式。 在编译时,查询表达式子句将被转换为对查询方法的调用。

查询表达式语法表

下表列出了具有等效查询表达式子句的标准查询运算符。 C# 和 Visual Basic 编程语言没有为相同方法提供专用查询表达式语法。 下表列出了同时适用于这两种语言的语法。

方法

C# 查询表达式语法

Visual Basic 查询表达式语法

All``1

不适用

Aggregate … In … Into All(…)

(有关更多信息,请参见 Aggregate 子句 (Visual Basic)。)

Any``1

不适用

Aggregate … In … Into Any()

(有关更多信息,请参见 Aggregate 子句 (Visual Basic)。)

Average

不适用

Aggregate … In … Into Average()

(有关更多信息,请参见 Aggregate 子句 (Visual Basic)。)

Cast``1

使用显式类型化的范围变量,例如:

from int i in numbers

(有关更多信息,请参见 from 子句(C# 参考)。)

From … As …

(有关更多信息,请参见 From 子句 (Visual Basic)。)

Count``1

不适用

Aggregate … In … Into Count()

(有关更多信息,请参见 Aggregate 子句 (Visual Basic)。)

Distinct``1(IEnumerableUMP)

不适用

Distinct

(有关更多信息,请参见 Distinct 子句 (Visual Basic)。)

GroupBy

group … by

- 或 -

group … by … into …

(有关更多信息,请参见 group 子句(C# 参考)。)

Group … By … Into …

(有关更多信息,请参见 Group By 子句 (Visual Basic)。)

GroupJoin``4(IEnumerableUMP, IEnumerableUMP, FuncUMP, UMP, FuncUMP, UMP, FuncUMP, IEnumerableUMP, UMP)

join … in … on … equals … into …

(有关更多信息,请参见 join 子句(C# 参考)。)

Group Join … In … On …

(有关更多信息,请参见 Group Join 子句 (Visual Basic)。)

Join``4(IEnumerableUMP, IEnumerableUMP, FuncUMP, UMP, FuncUMP, UMP, FuncUMP, UMP, UMP)

join … in … on … equals …

(有关更多信息,请参见 join 子句(C# 参考)。)

From x In …, y In … Where x.a = b.a

- 或 -

Join … [As …]In … On …

(有关更多信息,请参见 Join 子句 (Visual Basic)。)

LongCount``1

不适用

Aggregate … In … Into LongCount()

(有关更多信息,请参见 Aggregate 子句 (Visual Basic)。)

Max

不适用

Aggregate … In … Into Max()

(有关更多信息,请参见 Aggregate 子句 (Visual Basic)。)

Min

不适用

Aggregate … In … Into Min()

(有关更多信息,请参见 Aggregate 子句 (Visual Basic)。)

OrderBy``2(IEnumerableUMP, FuncUMP, UMP)

orderby

(有关更多信息,请参见 orderby 子句(C# 参考)。)

Order By

(有关更多信息,请参见 Order By 子句 (Visual Basic)。)

OrderByDescending``2(IEnumerableUMP, FuncUMP, UMP)

orderby … descending

(有关更多信息,请参见 orderby 子句(C# 参考)。)

Order By … Descending

(有关更多信息,请参见 Order By 子句 (Visual Basic)。)

Select

select

(有关更多信息,请参见 select 子句(C# 参考)。)

Select

(有关更多信息,请参见 Select 子句 (Visual Basic)。)

SelectMany

多个 from 子句。

(有关更多信息,请参见 from 子句(C# 参考)。)

多个 From 子句

(有关更多信息,请参见 From 子句 (Visual Basic)。)

Skip``1

不适用

Skip

(有关更多信息,请参见 Skip 子句 (Visual Basic)。)

SkipWhile

不适用

Skip While

(有关更多信息,请参见 Skip While 子句 (Visual Basic)。)

Sum

不适用

Aggregate … In … Into Sum()

(有关更多信息,请参见 Aggregate 子句 (Visual Basic)。)

Take``1

不适用

Take

(有关更多信息,请参见 Take 子句 (Visual Basic)。)

TakeWhile

不适用

Take While

(有关更多信息,请参见 Take While 子句 (Visual Basic)。)

ThenBy``2(IOrderedEnumerableUMP, FuncUMP, UMP)

orderby …, …

(有关更多信息,请参见 orderby 子句(C# 参考)。)

Order By …, …

(有关更多信息,请参见 Order By 子句 (Visual Basic)。)

ThenByDescending``2(IOrderedEnumerableUMP, FuncUMP, UMP)

orderby …, … descending

(有关更多信息,请参见 orderby 子句(C# 参考)。)

Order By …, … Descending

(有关更多信息,请参见 Order By 子句 (Visual Basic)。)

Where

where

(有关更多信息,请参见 where 子句(C# 参考)。)

Where

(有关更多信息,请参见 Where 子句 (Visual Basic)。)

请参见

参考

Enumerable

Queryable

概念

标准查询运算符概述

标准查询运算符按执行方式的分类