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