ICollection Interface

Definition

定義所有非泛型集合的大小、列舉值和同步處理方法。Defines size, enumerators, and synchronization methods for all nongeneric collections.

public interface class ICollection : System::Collections::IEnumerable
public interface 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
Derived
Attributes
Implements

Remarks

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>.

Properties

Count

取得 ICollection 中的元素數目。Gets the number of elements contained in the ICollection.

IsSynchronized

取得值,該值指出是否同步存取 ICollection (安全執行緒)。Gets a value indicating whether access to the ICollection is synchronized (thread safe).

SyncRoot

取得可用來同步存取 ICollection 的物件。Gets an object that can be used to synchronize access to the ICollection.

Methods

CopyTo(Array, Int32)

從特定的 ICollection 索引開始,將 Array 的項目複製到 ArrayCopies the elements of the ICollection to an Array, starting at a particular Array index.

GetEnumerator()

傳回逐一查看集合的列舉值。Returns an enumerator that iterates through a collection.

(Inherited from IEnumerable)

Extension Methods

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

Applies to

See also