何时使用收集&LT​​; T> VS名单< T> [英] when to use Collection<T> vs List<T>

查看:182
本文介绍了何时使用收集&LT​​; T> VS名单< 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;并保持数据在一个有序的方式,但只有公开列出的排序语义....

解决方案

因此​​,根据该文档,其中一份是拟作为集合的基类。其他的目的是用作容器

所以使用 名单,其中,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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆