IList、ICollection、IEnumerable 之辨析
来源:互联网 发布:软件企业评估减税 编辑:程序博客网 时间:2024/05/19 18:11
祖宗:IEnumerable
此接口只有一个方法 GetEnumerator();
是FrameWork为了实现迭代器模式设计的接口。所有继承了IEnumerable的类,要使用foreach迭代器时,就需要使用该方法。因此也只有实现了该接口的类才可以使用foreach。
ICollection继承自IEnumerable,IList继承自ICollection
这两个接口都是为了给集合提供一些公用的方法。只是分了两个层次,IList比ICollection多几个方法,增加,移除成员。可以简单理解为:ICollection主要针对静态集合;IList主要针对动态集合。
IList,ICollection,IEnumerable 在命名空间System.Collections中。
IList<T>,ICollection<T>,IEnumerable<T> 在System.Collections.Generic 命名空间中。
IList<T>,ICollection<T>,IEnumerable<T> 是2.0引入泛型以后新增的。主要是提高重用性与类型安全。
IEnumerable<T>继承自IEnumerable
ICollection<T>继承自IEnumerable<T>
IList<T>继承自ICollection<T>
因此可以完全使用泛型接口,而放弃使用ICollection和IList。泛型接口提供了更好的类型安全和编译时的检验。
补充:
IEnumerable<T>和IEnumerable都只有一个方法。ICollection<T>和ICollection的结构是不一样的。ICollection<T>比ICollection多几个方法。它包含了几个IList中的几个方法。也许是对以前的改进。
《转自》Valsun's Blog
http://blog.sina.com.cn/s/blog_586b6c05010096tl.html
- IList、ICollection、IEnumerable 之辨析
- IList,ICollection,IEnumerable辨析
- IList,ICollection,IEnumerable,IListIList,ICollection,IEnumerable辨析
- IList,ICollection,IEnumerable,IListIList,ICollection,IEnumerable辨析
- IEnumerable,ICollection ,IList ,ArrayList
- IList,ICollection,IEnumerable,IEnumerator,IQueryable
- IEnumerable、ICollection和IList接口
- IList,ICollection,IEnumerable,IEnumerator,IQueryable
- public abstract class CollectionBase:IList,ICollection,IEnumerable
- (原创)(C#随笔)IEnumerable< ICollection < IList区别
- C#中的 IList, ICollection ,IEnumerable 和 IEnumerator
- IList,ICollection,IEnumerable,IEnumerator,IQueryable详解
- IEnumerable,ICollection,IList,List之间的区别
- IEnumerable/ICollection/IList/List继承关系
- IEnumerable,ICollection,IList,List之间的区别
- IEnumerable,ICollection,IList,List之间的区别
- 如何选择使用IEnumerable, ICollection, IList
- 阐述集合类的接口(IEnumerable,IEnumerator,ICollection,IList,IDictionary)
- 写程序时如何提高效率
- 找回任务栏的显示桌面
- 对 SQL Server 2005 Analysis Services 的 HTTP 访问
- 在 HTML 与 JSP 中 怎么才能在 if 条件中 跳转页面 并且显示到对应页面的 里的话
- OLAP的基本多维分析操作
- IList、ICollection、IEnumerable 之辨析
- 绑定用户控件button事件
- 数据存储到什么地方?--内存分配
- rails "No route matches" 错误的解决方法
- JS Error:'document.form.name' 为空或不是对象
- 敖士伟 事务 体会一
- N81主题收藏
- Java编程那些事儿68——抽象类和接口(一)
- STL中容器的类型和基本特征——《c++ primer plus第五版》学习小结(转)