System.Collections.Immutable Namespace

System.Collections.Immutable 命名空間包含定義不可變集合的介面與類別。 The System.Collections.Immutable namespace contains interfaces and classes that define immutable collections. .NET Framework 4.5.NET Framework 4.5 開始即支援這些類別。 These classes are supported starting with .NET Framework 4.5.NET Framework 4.5. 使用這些類別可建置以桌面、Windows 市集Windows Store可攜式類別庫Portable Class Library及 Windows Phone 8 為目標的應用程式。 Use them to build apps that target the desktop, Windows 市集Windows Store, 可攜式類別庫Portable Class Library and Windows Phone 8.

類別

ImmutableArray

提供建立不可變陣列的方法;也就是說,一旦建立之後,便無法變更。Provides methods for creating an array that is immutable; meaning it cannot be changed once it is created.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableArray<T>.Builder

可寫入的陣列存取子,其可轉換為 ImmutableArray<T> 執行個體而不需配置額外的記憶體。A writable array accessor that can be converted into an ImmutableArray<T> instance without allocating extra memory.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableDictionary

提供一組 ImmutableDictionary<TKey,TValue> 類別執行個體的初始化方法。Provides a set of initialization methods for instances of the ImmutableDictionary<TKey,TValue> class.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableDictionary<TKey,TValue>.Builder

代表有少量或沒有記憶體配置變動的雜湊對應,此雜湊對應可以非常有效率的方式產生或建置於不可變的雜湊對應執行個體上。Represents a hash map that mutates with little or no memory allocations and that can produce or build on immutable hash map instances very efficiently.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableDictionary<TKey,TValue>

表示不可變、未排序之索引鍵和值的集合。Represents an immutable, unordered collection of keys and values.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableHashSet

提供一組 ImmutableHashSet<T> 類別執行個體的初始化方法。Provides a set of initialization methods for instances of the ImmutableHashSet<T> class.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableHashSet<T>.Builder

代表有少數或沒有記憶體配置變動的雜湊集,此雜湊集可以非常有效率的方式產生或建置於不可變的雜湊集執行個體上。Represents a hash set that mutates with little or no memory allocations and that can produce or build on immutable hash set instances very efficiently.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableHashSet<T>

代表不可變、未排序的雜湊集。Represents an immutable, unordered hash set.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableInterlocked

包含不可變集合之連鎖交換機制。Contains interlocked exchange mechanisms for immutable collections.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableList

提供一組 ImmutableList<T> 類別執行個體的初始化方法。Provides a set of initialization methods for instances of the ImmutableList<T> class.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableList<T>.Builder

代表有少量或沒有記憶體配置變動的清單,這個清單可以非常有效率的方式產生或建置於不可變的清單執行個體上。Represents a list that mutates with little or no memory allocations and that can produce or build on immutable list instances very efficiently.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableList<T>

表示一個可以依照索引存取強式型別物件的不可變清單。Represents an immutable list, which is a strongly typed list of objects that can be accessed by index.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableQueue

提供一組 ImmutableQueue<T> 類別執行個體的初始化方法。Provides a set of initialization methods for instances of the ImmutableQueue<T> class.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableQueue<T>

代表不可變的佇列。Represents an immutable queue.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedDictionary

提供一組 ImmutableSortedDictionary<TKey,TValue> 類別執行個體的初始化方法。Provides a set of initialization methods for instances of the ImmutableSortedDictionary<TKey,TValue> class.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedDictionary<TKey,TValue>.Builder

代表隨著少數記憶體配置或無記憶體配置而變動的排序字典,此排序字典可以非常有效率地產生或建置於不可變排序字典執行個體上。Represents a sorted dictionary that mutates with little or no memory allocations and that can produce or build on immutable sorted dictionary instances very efficiently.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedDictionary<TKey,TValue>

代表不可變排序字典。Represents an immutable sorted dictionary.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedSet

提供一組 ImmutableSortedSet<T> 類別執行個體的初始化方法。Provides a set of initialization methods for instances of the ImmutableSortedSet<T> class.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedSet<T>.Builder

代表排序的資料集,能夠進行少量或沒有記憶體配置的變更,有效率地操作或建立不可變的排序資料集。Represents a sorted set that enables changes with little or no memory allocations, and efficiently manipulates or builds immutable sorted sets.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedSet<T>

代表不可變的已排序資料集實作。Represents an immutable sorted set implementation.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableStack

提供一組 ImmutableStack<T> 類別執行個體的初始化方法。Provides a set of initialization methods for instances of the ImmutableStack<T> class.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableStack<T>

表示不可變的堆疊。Represents an immutable stack.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

結構

ImmutableArray<T>.Enumerator

陣列列舉程式。An array enumerator.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableArray<T>

代表不可變的陣列,意即在建立該陣列之後,就無法加以變更。Represents an array that is immutable; meaning it cannot be changed once it is created.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableDictionary<TKey,TValue>.Enumerator

列舉不可變字典內容且不配置記憶體。Enumerates the contents of the immutable dictionary without allocating any memory.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableHashSet<T>.Enumerator

列舉不可變雜湊集的內容而不配置任何記憶體。Enumerates the contents of the immutable hash set without allocating any memory.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableList<T>.Enumerator

列舉二進位樹狀目錄的內容。Enumerates the contents of a binary tree.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableQueue<T>.Enumerator

列舉不可變佇列的內容而不需配置任何記憶體。Enumerates the contents of an immutable queue without allocating any memory.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedDictionary<TKey,TValue>.Enumerator

列舉二進位樹狀目錄的內容。Enumerates the contents of a binary tree.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedSet<T>.Enumerator

列舉二進位樹狀目錄的內容。Enumerates the contents of a binary tree.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableStack<T>.Enumerator

列舉不可變堆疊的內容而不需配置任何記憶體。Enumerates the contents of an immutable stack without allocating any memory.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

介面

IImmutableDictionary<TKey,TValue>

表示索引鍵/值組的不可變集合。Represents an immutable collection of key/value pairs.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

IImmutableList<T>

代表無法修改之項目的清單。Represents a list of elements that cannot be modified.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

IImmutableQueue<T>

表示物件的不可變先進先出集合。Represents an immutable first-in, first-out collection of objects.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

IImmutableSet<T>

代表一組項目,您只能透過為該資料集建立新的執行個體來進行修改。Represents a set of elements that can only be modified by creating a new instance of the set.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

IImmutableStack<T>

表示不可變的後進先出 (LIFO) 集合。Represents an immutable last-in-first-out (LIFO) collection.

NuGet 套件System.Collections.Immutable (關於固定集合及其安裝方法)NuGet package: System.Collections.Immutable (about immutable collections and how to install)

備註

不可變的集合可讓您:With immutable collections, you can:

  • 共用其取用者可確保集合永遠不會變更的方法集合。Share a collection in a way that its consumer can be assured that the collection never changes.

  • 在多執行緒應用程式中提供隱含的執行緒安全性 (不需要鎖定,即可存取集合)。Provide implicit thread safety in multi-threaded applications (no locks required to access collections).

  • 依照函式程式設計作法進行。Follow functional programming practices.

  • 在列舉期間修改集合,並可確保原始集合不會變更。Modify a collection during enumeration, while ensuring that the original collection does not change.

不可變的集合類別可用於.NET Core,但它們不是.NET Framework 一起散發之核心類別庫的一部分。The immutable collection classes are available with .NET Core, however they're not part of the core class library distributed with the .NET Framework. 它們可透過 NuGet 的.NET Framework 4.5 開始。They're available starting with the .NET Framework 4.5 via NuGet.

若要安裝 NuGet 透過不可變的集合:To install the immutable collections via NuGet:

  1. 在 Visual Studio 中開啟您的專案,然後選擇管理 NuGet 套件專案功能表。Open your project in Visual Studio and choose Manage NuGet Packages from the Project menu.

  2. (選擇性) 選取包含發行前版本核取方塊。Optionally, select the Include prerelease checkbox. 此選項可讓您在不可變類別的新發行前版本推出時加以存取。This option will give you access to new prerelease versions of the immutable classes, as they become available.

  3. 使用搜尋方塊,以找出System.Collections.Immutable封裝。Use the Search box to locate the System.Collections.Immutable package.

  4. 在左窗格中,選取System.Collections.Immutable封裝。In the left pane, select the System.Collections.Immutable package. 在右窗格中,選取所需的版本,然後選擇安裝。In the right pane, select the desired version and then choose Install.

Visual Studio 2015,則上面所述的安裝步驟。The installation steps described above are for Visual Studio 2015. 對於其他版本的 Visual Studio 中,步驟可能稍有不同因為在使用者介面 (UI) 中的差異。For other versions of Visual Studio, the steps might be slightly different because of differences in the user interface (UI).