IEnumerable接口深入研究

sdfgrtyu 2015-01-08 03:14:56


public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
if (source == null) throw Error.ArgumentNull("source");
if (predicate == null) throw Error.ArgumentNull("predicate");
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);
return new WhereEnumerableIterator<TSource>(source, predicate);
}

public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) 这是什么?

能不能给解释一下上面的代码什么意思?

从这里我们就可以清晰地看到M$其实是包装了一层,怎么看出来包装了一层?

public override IEnumerable<TSource> Where(Func<TSource, bool> predicate) {
return new WhereListIterator<TSource>(source, CombinePredicates(this.predicate, predicate));
}这段代码又是什么?和上面的代码什么关系?

能不能给我解释一下?

...全文
175 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdfgrtyu 2015-01-09
  • 打赏
  • 举报
回复
顶一下
moonwrite 2015-01-08
  • 打赏
  • 举报
回复
不详细回答了 给你关键字 你自己好好百度一下 理解了我说的知识点 你就明白了 this: 扩展方法 where: 泛型约束 Fun<T : 泛型方法 只要你把上面的3个知识点理解了,你问的问题 你也就可以自己解决了
mnxm 2015-01-08
  • 打赏
  • 举报
回复
关系的话好像没什么吧 下面的是 重写方法 上面的是扩展方法
游离失所 2015-01-08
  • 打赏
  • 举报
回复
静态类中的静态方法,而且第一个参数为this 类型 xx的。。我们称为扩展方法 如果有某类型的实例A。。我们可以直接通过A.方法就可以进行调用了。。 下面那段代码明显就是重写。。至于有什么关系我就不知道了。。 http://bbs.csdn.net/topics/390951798 自己去看看吧。。 IEnumerable接口没什么好研究的,主要就是GetEnumerator方法 foreach,tolist,toarray都会用到它
mnxm 2015-01-08
  • 打赏
  • 举报
回复
public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) 这句不理解的话去搜索 方法扩展

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧