何时使用Collection< T> vs List< T> [英] when to use Collection<T> vs List<T>
本文介绍了何时使用Collection< T> vs List< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么时候使用一个vs谁的最佳实践?
What is the best practice for when to use one vs the other?
两者都实现IList< T&
Both implement IList<T> and hold the data in an ordered fashion, but only List expose the sorting semantics....
推荐答案
-
集合< T>
:
Collection<T>
:
提供通用
集合的基类。Provides the base class for a generic collection.
-
列表< T>
:
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.
所以使用 列表< T>
和继承来自集合< T>
。
这篇关于何时使用Collection< T> vs List< T>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文