ICollection Interface


定义所有非泛型集合的大小、枚举数和同步方法。Defines size, enumerators, and synchronization methods for all nongeneric collections.

public interface class ICollection : System::Collections::IEnumerable
public interface ICollection : System.Collections.IEnumerable
public interface ICollection : System.Collections.IEnumerable
type ICollection = interface
    interface IEnumerable
Public Interface ICollection
Implements IEnumerable


ICollection 接口是 System.Collections 命名空间中的类的基接口。The ICollection interface is the base interface for classes in the System.Collections namespace. 它的泛型等效项是 System.Collections.Generic.ICollection<T> 接口。Its generic equivalent is the System.Collections.Generic.ICollection<T> interface.

ICollection 接口扩展 IEnumerable;IDictionaryIList 是扩展 ICollection的专用接口。The ICollection interface extends IEnumerable; IDictionary and IList are more specialized interfaces that extend ICollection. IDictionary 实现是键/值对的集合,如 Hashtable 类。An IDictionary implementation is a collection of key/value pairs, like the Hashtable class. IList 实现是值的集合,其成员可以按索引访问,就像 ArrayList 类一样。An IList implementation is a collection of values and its members can be accessed by index, like the ArrayList class.

某些限制对其元素(例如 Queue 类和 Stack 类)的访问的集合直接实现 ICollection 接口。Some collections that limit access to their elements, such as the Queue class and the Stack class, directly implement the ICollection interface.

如果 IDictionary 接口和 IList 接口都不满足所需集合的要求,则改为从 ICollection 接口派生新的集合类,以便获得更大的灵活性。If neither the IDictionary interface nor the IList interface meet the requirements of the required collection, derive the new collection class from the ICollection interface instead for more flexibility.

有关此接口的泛型版本,请参阅 System.Collections.Generic.ICollection<T>For the generic version of this interface, see System.Collections.Generic.ICollection<T>.



获取 ICollection 中包含的元素数。Gets the number of elements contained in the ICollection.


获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。Gets a value indicating whether access to the ICollection is synchronized (thread safe).


获取可用于同步对 ICollection 的访问的对象。Gets an object that can be used to synchronize access to the ICollection.


CopyTo(Array, Int32)

从特定的 ICollection 索引开始,将 Array 的元素复制到一个 Array 中。Copies the elements of the ICollection to an Array, starting at a particular Array index.


返回循环访问集合的枚举器。Returns an enumerator that iterates through a collection.

(Inherited from IEnumerable)

Extension Methods


IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.


根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.


启用查询的并行化。Enables parallelization of a query.


IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Applies to

See also