System.Collections.Immutable Namespace

The System.Collections.Immutable namespace contains interfaces and classes that define immutable collections. These classes are supported starting with .NET Framework 4.5. Use them to build apps that target the desktop, Windows Store, Portable Class Library and Windows Phone 8.

Classes

ImmutableArray

Provides methods for creating an array that is immutable; meaning it cannot be changed once it is created.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableArray<T>.Builder

A writable array accessor that can be converted into an ImmutableArray<T> instance without allocating extra memory.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableDictionary

Provides a set of initialization methods for instances of the ImmutableDictionary<TKey,TValue> class.

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 package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableDictionary<TKey,TValue>

Represents an immutable, unordered collection of keys and values.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableHashSet

Provides a set of initialization methods for instances of the ImmutableHashSet<T> class.

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 package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableHashSet<T>

Represents an immutable, unordered hash set.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableInterlocked

Contains interlocked exchange mechanisms for immutable collections.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableList

Provides a set of initialization methods for instances of the ImmutableList<T> class.

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 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 package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableQueue

Provides a set of initialization methods for instances of the ImmutableQueue<T> class.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableQueue<T>

Represents an immutable queue.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedDictionary

Provides a set of initialization methods for instances of the ImmutableSortedDictionary<TKey,TValue> class.

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 package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedDictionary<TKey,TValue>

Represents an immutable sorted dictionary.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedSet

Provides a set of initialization methods for instances of the ImmutableSortedSet<T> class.

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 package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedSet<T>

Represents an immutable sorted set implementation.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableStack

Provides a set of initialization methods for instances of the ImmutableStack<T> class.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableStack<T>

Represents an immutable stack.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

Structs

ImmutableArray<T>.Enumerator

An array enumerator.

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 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 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 package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableList<T>.Enumerator

Enumerates the contents of a binary tree.

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 package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedDictionary<TKey,TValue>.Enumerator

Enumerates the contents of a binary tree.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

ImmutableSortedSet<T>.Enumerator

Enumerates the contents of a binary tree.

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 package: System.Collections.Immutable (about immutable collections and how to install)

Interfaces

IImmutableDictionary<TKey,TValue>

Represents an immutable collection of key/value pairs.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

IImmutableList<T>

Represents a list of elements that cannot be modified.

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 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 package: System.Collections.Immutable (about immutable collections and how to install)

IImmutableStack<T>

Represents an immutable last-in-first-out (LIFO) collection.

NuGet package: System.Collections.Immutable (about immutable collections and how to install)

Remarks

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.

The immutable collection classes are available with .NET Core, however they're not part of the core class library distributed with the .NET Framework. They're available starting with the .NET Framework 4.5 via NuGet.

To install the immutable collections via NuGet:

  1. 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. Use the Search box to locate the System.Collections.Immutable package.

  4. In the left pane, select the System.Collections.Immutable package. In the right pane, select the desired version and then choose Install.

The installation steps described above are for Visual Studio 2015. For other versions of Visual Studio, the steps might be slightly different because of differences in the user interface (UI).