何时使用收集&LT; T&GT; VS名单&LT; T&GT; [英] when to use Collection<T> vs List<T>
问题描述
可能重复:
之间的区别
<一href="http://stackoverflow.com/questions/398903/what-is-the-difference-between-list-of-t-and-collectionof-t">What是列表(的T)和集合(T)的?
什么是当使用一个相较于其他的最佳做法是什么?
这两种实现IList&LT; T&GT;并保持数据在一个有序的方式,但只有公开列出的排序语义....
-
收藏&LT; T&GT;
:提供的基类的通用 集合。
-
名单,其中,T&GT;
:再presents的强类型列表 这可以通过索引访问的对象。 提供的方法进行搜索,排序和 操作列表。
因此,根据该文档,其中一份是拟作为集合的基类。其他的目的是用作容器
所以使用 名单,其中,T&GT;
和继承从收藏&LT; T&GT;
。
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>
.
这篇关于何时使用收集&LT; T&GT; VS名单&LT; T&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!