首页 > 其他 > 详细

Linq源代码阅读

时间:2017-01-23 15:19:10      阅读:196      评论:0      收藏:0      [点我收藏+]

在 System.Core

dotnet451\source\ndp\fx\src\core\system\linq\enumerable.cs

 

Where 和 Select 内 ,把数组和List分开,没看明白为什么这么做

if (source is Iterator<TSource>) return ((Iterator<TSource>)source).Where(predicate);
if (source is TSource[]) return new WhereArrayIterator<TSource>((TSource[])source, predicate);
if (source is List<TSource>) return new WhereListIterator<TSource>((List<TSource>)source, predicate);

----------------------

Union,Intersect,Except,Distinct 防止重复 用Set,类似HashSet一个内部使用的,没明白为什么不用Hashset,可能是为了简化?

HashSet类似用字典,但是只有Key,没有Value

Union,联合,A + B, 加后元素都不会重复。

Intersect  交集, A和B共同有的, A如果本来有重复的元素,也只取一个,

  Join A B类型不同,Intersect类型相同

Except 差集,A有 B没有的元素 ,A如果本来有重复的元素,也只取一个

 

-------------------

SequenceEqual 两个序列元素比较,长度也要一样

AsEnumerable 没有任何意义

 IEnumerable<TResult> OfType<TResult>(this IEnumerable source)  只返回source里 TResult类型的。

OfType 用的is type ,Cast用的(TResult)type ,可能转 double 到int适合Cast

----------------------------------------

Join以前看过,排序和分组的没仔细看。

 

Linq源代码阅读

原文:http://www.cnblogs.com/peteryu007/p/6343964.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!