做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,好了,送给一些不知道的同学们,大牛们,路过麻烦补充下,谢谢!

【转载】我也说 IEnumerable,ICollection,IList,List之间的区别的更多相关文章

  1. IEnumerable,ICollection,IList,List之间的区别

    做C#的同学们,都知道,一类只能有一个继承类,但可以实现多个接口.这句话就告诉我们:IEnumerable,ICollection,IList,List区别了 // 摘要: // 公开枚举器,该枚举器 ...

  2. 服务器文档下载zip格式 SQL Server SQL分页查询 C#过滤html标签 EF 延时加载与死锁 在JS方法中返回多个值的三种方法(转载) IEnumerable,ICollection,IList接口问题 不吹不擂,你想要的Python面试都在这里了【315+道题】 基于mvc三层架构和ajax技术实现最简单的文件上传 事件管理

    服务器文档下载zip格式   刚好这次项目中遇到了这个东西,就来弄一下,挺简单的,但是前台调用的时候弄错了,浪费了大半天的时间,本人也是菜鸟一枚.开始吧.(MVC的) @using Rattan.Co ...

  3. IEnumerable<> ICollection <> IList<> 区别

    IEnumerable< ICollection < IList区别 public interface IEnumerable { IEnumerator GetEnumerator(); ...

  4. Asp.Net IEnumerable,ICollection,IList,List区别

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

  5. IEnumerable,ICollection,IList,List区别

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

  6. 如何选择使用IEnumerable, ICollection, IList

    IEnumerable, ICollection, IList,每种接口只适合某些特定场景,如何区别使用呢? IEnumerable接口,只提供了一个获取迭代器的方法,这也是为什么可以使用foreac ...

  7. IEnumerable,ICollection,IList,List的使用

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

  8. (原创)(C#随笔)IEnumerable< ICollection < IList区别

    public interface IEnumerable { IEnumerator GetEnumerator(); } 再看ICollection<T> public interfac ...

  9. IEnumerable,ICollection,IList接口问题

    最近有一个疑问:IList已经继承了ICollection<T>,而ICollection<T>继承了 IEnumerable<T>, IEnumerable,那为 ...

随机推荐

  1. js复制input 框中的值

    function copy(){ var Url2=document.getElementById("copyValue"); Url2.select(); document.ex ...

  2. EF6+MVC5之Oracleo数据库的Code First方式实现

    折腾了好几天,在办公室机器上死活找不到ODP.net的Oracle数据库连接方式(但在家中电脑上正常).后来把之前安装的VS2013和所以安装的Oracle客气端统统卸载,重新安装visual stu ...

  3. Python学习笔记(二)基本语法

    Class 2 一.交互式编程 交互式编程不需要创建脚本文件,是通过 Python 解释器的交互模式进来编写代码. linux上你只需要在命令行中输入 Python 命令即可启动交互式编程,如下图: ...

  4. exports 和 module.exports 的区别

    https://cnodejs.org/topic/5231a630101e574521e45ef8 //一句话总结:exports是对module.exports的引用,require()返回的是 ...

  5. VC++ operate excel

    利用VC操作Excel的方法至少有两种 1 .利用ODBC把Excel文件当成数据库文件,来进行读.写.修改等操作,网上有人编写了CSpreadSheet类,提供支持. 2. 利用Automation ...

  6. SqlServer2008R2附件数据库失败

    MSSQL附加数据库时提示以下错误: 无法打开物理文件“***.mdf”.操作系统错误 5:“5(拒绝访问.)”. (Microsoft SQL Server,错误: 5120) 该经验介绍如何处理该 ...

  7. ubuntu 14 配置 tomcat

    参考 http://www.linuxidc.com/Linux/2015-01/111119.htm

  8. afterTextChanged() callback being called without the text being actually changed

    afterTextChanged() callback being called without the text being actually changed up vote8down votefa ...

  9. dojo 加载Json数据

    1.今天研究了dojo datagrid加载WebService后台传上来的数据.研究来研究去发现他不是很难.用谷歌多调试一下就好了. 2.看很多例子,这个例子能够更好的帮我解决问题:https:// ...

  10. TCP/ip协议栈之内核调优

    大并发带来服务器各种层出不穷的问题,我们要善用服务器系统内核,因为其性能优于用户态的玩意 注:若想永久保存参数,可将其加入到/etc/sysctl.conf中,执行sysctl -p使其永久生效,临时 ...