系列目录    【已更新最新开发文章,点击查看详细】 <https://www.cnblogs.com/SavionZhang/p/11229640.html>
标准查询运算符方法的 LINQ to Objects 实现主要通过两种方法之一执行:立即执行和延迟执行。
使用延迟执行的查询运算符可以进一步分为两种类别:流式处理和非流式处理。 如果你了解不同查询运算符的执行方式,则有助于理解从给定查询中获得的结果。 
如果数据源是不断变化的,或者如果你要在另一个查询的基础上构建查询,这种帮助尤其明显。 本篇根据标准查询运算符的执行方式对其进行分类。
执行方式
即时

立即执行指的是在代码中声明查询的位置读取数据源并执行运算。 返回单个不可枚举的结果的所有标准查询运算符都立即执行。

推迟

延迟执行指的是不在代码中声明查询的位置执行运算。 仅当对查询变量进行枚举时才执行运算,例如通过使用 foreach 语句执行。 
这意味着,查询的执行结果取决于执行查询而非定义查询时的数据源内容。 如果多次枚举查询变量,则每次结果可能都不同。 几乎所有返回类型为 
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
 或 IOrderedEnumerable<TElement>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.iorderedenumerable-1>
 的标准查询运算符皆以延迟方式执行。

使用延迟执行的查询运算符可以另外分类为流式处理和非流式处理。

流式处理

流式处理运算符不需要在生成元素前读取所有源数据。 在执行时,流式处理运算符一边读取每个源元素,一边对该源元素执行运算,并在可行时生成元素。 
流式处理运算符将持续读取源元素直到可以生成结果元素。 这意味着可能要读取多个源元素才能生成一个结果元素。

非流式处理

非流式处理运算符必须先读取所有源数据,然后才能生成结果元素。 排序或分组等运算均属于此类别。 
在执行时,非流式处理查询运算符将读取所有源数据,将其放入数据结构,执行运算,然后生成结果元素。
分类表 下表按照执行方法对每个标准查询运算符方法进行了分类。 如果某个运算符被标入两个列中,则表示在运算中涉及两个输入序列,每个序列的计算方式不同。 
在此类情况下,参数列表中的第一个序列始终以延迟流式处理方式来执行计算。
标准查询运算符返回类型立即执行延迟的流式处理执行延迟非流式处理执行
Aggregate
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.aggregate>
TSource X    
All <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.all>
Boolean <https://docs.microsoft.com/zh-cn/dotnet/api/system.boolean> X    
Any <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.any>
Boolean <https://docs.microsoft.com/zh-cn/dotnet/api/system.boolean> X    
AsEnumerable
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.asenumerable>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
Average
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.average>
单个数值 X    
Cast <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.cast>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
Concat
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.concat>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
Contains
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.contains>
Boolean <https://docs.microsoft.com/zh-cn/dotnet/api/system.boolean> X    
Count
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.count> Int32
<https://docs.microsoft.com/zh-cn/dotnet/api/system.int32> X    
DefaultIfEmpty
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.defaultifempty>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
Distinct
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.distinct>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
ElementAt
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.elementat>
TSource X    
ElementAtOrDefault
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.elementatordefault>
TSource X    
Empty
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.empty>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
X    
Except
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.except>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X X
First
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.first>
TSource X    
FirstOrDefault
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.firstordefault>
TSource X    
GroupBy
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.groupby>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
    X
GroupJoin
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.groupjoin>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X X
Intersect
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.intersect>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X X
Join <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.join>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X X
Last <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.last>
TSource X    
LastOrDefault
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.lastordefault>
TSource X    
LongCount
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.longcount>
Int64 <https://docs.microsoft.com/zh-cn/dotnet/api/system.int64> X    
Max <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.max>
单个数值、TSource 或 TResult X    
Min <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.min>
单个数值、TSource 或 TResult X    
OfType
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.oftype>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
OrderBy
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.orderby>
IOrderedEnumerable<TElement>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.iorderedenumerable-1>  
  X
OrderByDescending
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.orderbydescending>
IOrderedEnumerable<TElement>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.iorderedenumerable-1>  
  X
Range
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.range>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
Repeat
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.repeat>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
Reverse
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.reverse>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
    X
Select
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.select>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
SelectMany
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.selectmany>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
SequenceEqual
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.sequenceequal>
Boolean <https://docs.microsoft.com/zh-cn/dotnet/api/system.boolean> X    
Single
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.single>
TSource X    
SingleOrDefault
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.singleordefault>
TSource X    
Skip <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.skip>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
SkipWhile
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.skipwhile>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
Sum <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.sum>
单个数值 X    
Take <https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.take>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
TakeWhile
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.takewhile>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
ThenBy
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.thenby>
IOrderedEnumerable<TElement>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.iorderedenumerable-1>  
  X
ThenByDescending
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.thenbydescending>
IOrderedEnumerable<TElement>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.iorderedenumerable-1>  
  X
ToArray
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.toarray>
TSource 数组 X    
ToDictionary
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.todictionary>
Dictionary<TKey,TValue>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.dictionary-2>
X    
ToList
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.tolist>
IList<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ilist-1>
X    
ToLookup
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.tolookup>
ILookup<TKey,TElement>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.ilookup-2> X    
Union
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.union>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X  
Where
<https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.where>
IEnumerable<T>
<https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.ienumerable-1>
  X

  系列目录    【已更新最新开发文章,点击查看详细】
<https://www.cnblogs.com/SavionZhang/p/11229640.html>

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信