做C#的都知道:一类只能有一个继承类,但可以实现多个接口。这句话就告诉我们:IEnumerable,ICollection,IList,List区别了

首先我看看 IEnumerable:

 
// 摘要:
// 公开枚举器,该枚举器支持在指定类型的集合上进行简单迭代。
//
// 类型参数:
// T:
// 要枚举的对象的类型。
[TypeDependency("System.SZArrayHelper")]
public interface IEnumerable<out T> : IEnumerable
{
// 摘要:
// 返回一个循环访问集合的枚举器。
//
// 返回结果:
// 可用于循环访问集合的 System.Collections.Generic.IEnumerator<T>。
IEnumerator<T> GetEnumerator();
}
 

IEnumerable<T> 实现IEnumerable接口方法,那IEnumberable做什么的,其实就提高可以循环访问的集合。说白了就是一个迭代。

再来看看ICollection:

 
    // 摘要:
// 定义操作泛型集合的方法。
//
// 类型参数:
// T:
// 集合中元素的类型。
[TypeDependency("System.SZArrayHelper")]
public interface ICollection<T> : IEnumerable<T>, IEnumerable
 

原来ICollection<T> 同时继承IEnumerable<T>和IEnumerable两个接口,按我的理解就是,ICollection继续它们2个接口而且扩展了方法,功能强多了。 由原来的步枪变成半自动步枪

我们继续看IList:

public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable

靠 IList 继承它们三个接口,怪不得功能这么多啊,那应该属于全自动步枪了

最后来看看List:

public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable

这个时候大家仔细看看,它们都是接口,只有List 是类,不仅实现它们的接口,而且还扩展了太多的方法给我利用。哇靠,几乎所有功能都能实现了,简直是激光步枪

按照功能排序:List<T> -> IList<T> -> ICollection<T> -> IEnumerable<T>

按照性能排序:IEnumerable<T> -> ICollection<T> -> IList<T> -> List<T>

那同学们,是不是可以根据自身的需求调用不能数组来实现功能,不要一味使用List,好了,送给一些不知道的同学们,大牛们,路过麻烦补充下,谢谢!

最新文章

  1. How Google TestsSoftware - The Life of a SET
  2. [知识库分享系列] 二、.NET(ASP.NET)
  3. Kernel rest_init相关
  4. 几种更新(Update语句)查询的方法
  5. Radar Installation 贪心
  6. [IOS]UIWebView 请求网络页面或者加载本地资源页面
  7. /-- Encapsulated exception ------------\ java.lang.NoSuchMethodException: com.sjzdaj.po.Class.setN_id([Ljava.lang.String;)
  8. JS、JQuery和ExtJs动态创建DOM对象
  9. 201521123004 《Java程序设计》第12周学习总结
  10. [Machine Learning]学习笔记-线性回归
  11. java的this关键字理解
  12. host大法之GitHub上不去
  13. 快速搭建BIND服务,并实现解析
  14. 洛谷.2754.星际转移问题(最大流Dinic 分层)
  15. android TableLayOut画表格
  16. jQuery学习笔记:基础
  17. WCF:该不该用枚举值
  18. Python虚拟环境包导出
  19. Visual Studio 2017 发布 附带下载地址
  20. 【MySQL 数据库】MySQL目录

热门文章

  1. exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  2. Hadoop FairScheduler
  3. eclipse修改代码没用、debug无法进断点、
  4. DICOM中的UID
  5. Mercurial 安装及使用
  6. FTO Obesity Variant Circuitry and Adipocyte Browning in Humans
  7. Linux(环境篇):系统搭建本地FTP后,无法登录(331 Please specify the password.)问题解决
  8. arcpy地理处理工具案例教程-景观形状指数计算
  9. 阿里云mysql数据库恢复到本地
  10. Linux内核链表——看这一篇文章就够了