ICollection 介面

定義

定義所有非泛型集合的大小、列舉值和同步處理方法。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
[<System.Runtime.InteropServices.ComVisible(true)>]
type ICollection = interface
    interface IEnumerable
Public Interface ICollection
Implements IEnumerable
衍生
屬性
實作

備註

ICollection介面是命名空間中類別的基底介面 System.CollectionsThe 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介面可延伸 IEnumerableIDictionary 而且 IList 是更專門擴充的介面 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

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

方法

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.

(繼承來源 IEnumerable)

擴充方法

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.

適用於

另請參閱