且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

何时使用Collection< T> vs List< T>

更新时间:2022-03-20 23:33:26


  • 集合< 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>