ICollection ICollection ICollection 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
type ICollection = interface
    interface IEnumerable
Public Interface ICollection
Implements IEnumerable


接口是System.Collections命名空间中的类的基接口。 ICollectionThe 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;和是更专用的扩展ICollection接口。 IList IDictionaryThe ICollection interface extends IEnumerable; IDictionary and IList are more specialized interfaces that extend ICollection. 实现是键/值对的集合, Hashtable如类。 IDictionaryAn IDictionary implementation is a collection of key/value pairs, like the Hashtable class. 实现是值的集合, 其成员可以按索引访问, ArrayList如类。 IListAn IList implementation is a collection of values and its members can be accessed by index, like the ArrayList class.

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

如果IDictionary接口ICollection和接口都不满足所需集合的要求, 请改为从接口派生新的集合类以获得更大的灵活性。 IListIf 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>.


Count Count Count Count

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

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

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

SyncRoot SyncRoot SyncRoot SyncRoot

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


CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

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

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

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

(Inherited from IEnumerable)


Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

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

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.