可能重复: What是列表(的T)和集合(T)的?
之间的区别什么是当使用一个相较于其他的最佳做法是什么?
这两种实现IList< T>并保持数据在一个有序的方式,但只有公开列出的排序语义....
解决方案收藏< T>
:
提供的基类的通用 集合。
名单,其中,T>
:
再presents的强类型列表 这可以通过索引访问的对象。 提供的方法进行搜索,排序和 操作列表。
因此,根据该文档,其中一份是拟作为集合的基类。其他的目的是用作容器
所以使用 名单,其中,T>
和继承从收藏< T>
。
Possible Duplicate: What is the difference between List (of T) and Collection(of T)?
What is the best practice for when to use one vs the other?
Both implement IList<T> and hold the data in an ordered fashion, but only List expose the sorting semantics....
解决方案
Collection<T>
:
Provides the base class for a generic collection.
List<T>
:
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.
So, according the docs, one is intended as a base class for collections. The other is intended for use as a container.
So use List<T>
and inherit from Collection<T>
.