为什么不IEnumerable的< T>添加工具(T)? [英] Why doesn't IEnumerable<T> implement Add(T)?

查看:217
本文介绍了为什么不IEnumerable的< T>添加工具(T)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚才发现一个偶然的机会,加入(T)的的ICollection&LT被定义C $ C>。而在Enumerable.cs扩展方法不包括添加(T),我认为这是非常奇怪的。由于对象是枚举,它必须看起来像项目的集合。谁能告诉我为什么?

Just now find it by chance, Add(T) is defined in ICollection<T>, instead of IEnumerable<T>. And extension methods in Enumerable.cs don't contain Add(T), which I think is really weird. Since an object is enumerable, it must "looks like" a collection of items. Can anyone tell me why?

推荐答案

这是的IEnumerable&LT; T&GT; 是只是元素的顺序;认为这是一个仅正向游标。因为很多这些序列是产生价值的数据,或从数据库中记录集流,这是没有意义的添加的项目给他们。

An IEnumerable<T> is just a sequence of elements; see it as a forward only cursor. Because a lot of those sequences are generating values, streams of data, or record sets from a database, it makes no sense to Add items to them.

这篇关于为什么不IEnumerable的&LT; T&GT;添加工具(T)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆