ICollection ICollection ICollection ICollection Interface

定义

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

public interface class ICollection : System::Collections::IEnumerable
[System.Runtime.InteropServices.ComVisible(true)]
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是扩展的更多专用的接口ICollectionThe 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>.

属性

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.

适用于

另请参阅