什么是IEnumerable和阵列的IList和List之间的区别? [英] What's the difference between IEnumerable and Array, IList and List?
问题描述
有什么的IEnumerable
和阵列
?
有什么的IList
和列表
?
这些似乎具有相同的功能。
These seem to have the same function.
推荐答案
的IEnumerable只提供少量的迭代功能。你可以遍历序列,但仅此而已。这具有的缺点 - 例如,这是非常低效的使用的IEnumerable元素,或获得第n个元素数 - 但它具有优势太 - 例如,一个IEnumerable可以是环形序列,像素数的序列。
IEnumerable provides only minimal "iterable" functionality. You can traverse the sequence, but that's about it. This has disadvantages -- for example, it is very inefficient to count elements using IEnumerable, or to get the nth element -- but it has advantages too -- for example, an IEnumerable could be an endless sequence, like the sequence of primes.
数组是固定大小的集合,随机存取(即你可以索引到它)。
Array is a fixed-size collection with random access (i.e. you can index into it).
List是一个大小可变的集合(即你可以添加和删除元素),随机存取。
List is a variable-size collection (i.e. you can add and remove elements) with random access.
IList的是抽象列表功能(计数,添加,删除,索引访问)从各种具体类,如List,的BindingList,的ObservableCollection等。
IList is an interface which abstracts list functionality (count, add, remove, indexer access) away from the various concrete classes such as List, BindingList, ObservableCollection, etc.
这篇关于什么是IEnumerable和阵列的IList和List之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!