ICollection 介面

定義

定義所有非泛型集合的大小、列舉值和同步處理方法。

C#
public interface ICollection : System.Collections.IEnumerable
C#
[System.Runtime.InteropServices.ComVisible(true)]
public interface ICollection : System.Collections.IEnumerable
衍生
屬性
實作

備註

ICollection 介面是 System.Collections 命名空間中類別的基底介面。 其泛型對等專案是 System.Collections.Generic.ICollection<T> 介面。

ICollection 介面會擴充 IEnumerable;IDictionaryIList 是擴充 ICollection的更特製化介面。 IDictionary 實作是索引鍵/值組的集合,例如 Hashtable 類別。 IList 實作是值的集合,而且其成員可以透過索引存取,例如 ArrayList 類別。

某些集合會限制其元素的存取,例如 Queue 類別和 Stack 類別,直接實作 ICollection 介面。

如果 IDictionary 介面和 IList 介面都不符合必要集合的需求,請改為從 ICollection 介面衍生新的集合類別,以獲得更大的彈性。

如需此介面的泛型版本,請參閱 System.Collections.Generic.ICollection<T>

屬性

Count

取得包含在 ICollection中的項目數目。

IsSynchronized

取得值,指出是否同步存取 ICollection (線程安全)。

SyncRoot

取得對象,這個物件可用來同步存取 ICollection

方法

CopyTo(Array, Int32)

從特定 Array 索引開始,將 ICollection 的專案複製到 Array

GetEnumerator()

傳回逐一查看集合的列舉值。

(繼承來源 IEnumerable)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別篩選 IEnumerable 的專案。

AsParallel(IEnumerable)

啟用查詢的平行處理。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

另請參閱