IEnumerable VS IList

使用LINQ中从集合中查询数据时,我们使用IEnumerable和IList进行数据操作。 IList继承自IEnumerable,因此它具有它的所有功能,除此之外,它有自己的功能。 IList比IEnumerable具有以下优势。 在上一篇文章中,我解释了IEnumerable和IQueryable之间的区别。

 

IList

  1. IList存在于System.Collections命名空间中。

  2. IList用于访问列表中特定位置/索引中的元素。

  3. 像IEnumerable一样,IList也最好从列表,数组等内存中的集合查询数据。

  4. 当您要从列表中添加或删除项目时,IList很有用。

  5. IList可以在不迭代集合的情况下找出集合中的元素的数量。

  6. IList支持延迟执行。

  7. IList不支持进一步过滤。

 

IEnumerable

  1. IEnumerable存在于System.Collections命名空间中。

  2. IEnumerable只能在集合上向前移动,它不能向后移动和在Item之间移动。

  3. IEnumerable最好从列表,数组等内存中的集合查询数据。

  4. IEnumerable不支持从列表中添加或删除项目。

  5. 使用IEnumerable,我们可以在迭代集合后找出集合中的元素的数量。

  6. IEnumerable支持延迟执行。

  7. IEnumerable支持进一步的过滤。

posted @ 2017-09-01 18:36  X-Cracker  阅读(565)  评论(0编辑  收藏  举报