系列目录 【已更新最新开发文章,点击查看详细】 <https://www.cnblogs.com/SavionZhang/p/11229640.html>
某些使用更频繁的标准查询运算符具有专用的 C# 语言关键字语法,使用这些语法可以在查询表达式中调用这些运算符。
查询表达式是比基于方法的等效项更具可读性的另一种查询表示形式。 查询表达式子句在编译时被转换为对查询方法的调用。
查询表达式语法表
下表列出包含等效查询表达式子句的标准查询运算符。
方法 C# 查询表达式语法
Cast <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.cast>
使用显式类型化范围变量,例如:from int i in numbers
(有关详细信息,请参阅 from 子句
<https://www.cnblogs.com/SavionZhang/p/使用显式类型化范围变量,例如:from%20int%20i%20in%20numbers(有关详细信息,请参阅%20from%20子句。)>
)
GroupBy
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.groupby>
group … by 或 group … by … into …
(有关详细信息,请参阅 group 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/group-clause>
)
GroupJoin<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>,
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.groupjoin#System_Linq_Enumerable_GroupJoin__4_System_Collections_Generic_IEnumerable___0__System_Collections_Generic_IEnumerable___1__System_Func___0___2__System_Func___1___2__System_Func___0_System_Collections_Generic_IEnumerable___1____3__>
IEnumerable<TInner>, Func<TOuter,TKey>, Func<TInner,TKey>,
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.groupjoin#System_Linq_Enumerable_GroupJoin__4_System_Collections_Generic_IEnumerable___0__System_Collections_Generic_IEnumerable___1__System_Func___0___2__System_Func___1___2__System_Func___0_System_Collections_Generic_IEnumerable___1____3__>
Func<TOuter,IEnumerable<TInner>,TResult>)
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.groupjoin#System_Linq_Enumerable_GroupJoin__4_System_Collections_Generic_IEnumerable___0__System_Collections_Generic_IEnumerable___1__System_Func___0___2__System_Func___1___2__System_Func___0_System_Collections_Generic_IEnumerable___1____3__>
join … in … on … equals … into …
(有关详细信息,请参阅 join 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/join-clause>
)
Join<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>,
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.join#System_Linq_Enumerable_Join__4_System_Collections_Generic_IEnumerable___0__System_Collections_Generic_IEnumerable___1__System_Func___0___2__System_Func___1___2__System_Func___0___1___3__>
IEnumerable<TInner>, Func<TOuter,TKey>, Func<TInner,TKey>,
Func<TOuter,TInner,TResult>)
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.join#System_Linq_Enumerable_Join__4_System_Collections_Generic_IEnumerable___0__System_Collections_Generic_IEnumerable___1__System_Func___0___2__System_Func___1___2__System_Func___0___1___3__>
join … in … on … equals … into …
(有关详细信息,请参阅 join 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/join-clause>
)
OrderBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.orderby#System_Linq_Enumerable_OrderBy__2_System_Collections_Generic_IEnumerable___0__System_Func___0___1__>
orderby
(有关详细信息,请参阅 orderby 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/orderby-clause>
)
OrderByDescending<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.orderbydescending#System_Linq_Enumerable_OrderByDescending__2_System_Collections_Generic_IEnumerable___0__System_Func___0___1__>
orderby
(有关详细信息,请参阅 orderby 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/orderby-clause>
)
Select
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.select>
select
(有关详细信息,请参阅 let 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/select-clause>
)
SelectMany
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.selectmany>
多个 from 子句。
(有关详细信息,请参阅 from 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/from-clause>
)
ThenBy<TSource,TKey>(IOrderedEnumerable<TSource>, Func<TSource,TKey>)
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.thenby#System_Linq_Enumerable_ThenBy__2_System_Linq_IOrderedEnumerable___0__System_Func___0___1__>
orderby …, …
(有关详细信息,请参阅 orderby 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/orderby-clause>
)
ThenByDescending<TSource,TKey>(IOrderedEnumerable<TSource>,
Func<TSource,TKey>)
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.thenbydescending#System_Linq_Enumerable_ThenByDescending__2_System_Linq_IOrderedEnumerable___0__System_Func___0___1__>
orderby …, … descending
(有关详细信息,请参阅 orderby 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/orderby-clause>
)
Where
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.where>
where
(有关详细信息,请参阅 where 子句
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/where-clause>
)
热门工具 换一换