Immutable collections

suggest change

The System.Collections.Immutable NuGet package provides immutable collection classes.

Creating and adding items

var stack = ImmutableStack.Create<int>();
var stack2 = stack.Push(1); // stack is still empty, stack2 contains 1
var stack3 = stack.Push(2); // stack2 still contains only one, stack3 has 2, 1

Creating using the builder

Certain immutable collections have a Builder inner class that can be used to cheaply build large immutable instances:

var builder = ImmutableList.CreateBuilder<int>(); // returns ImmutableList.Builder
builder.Add(1);
builder.Add(2);
var list = builder.ToImmutable();

Creating from an existing IEnumerable

var numbers = Enumerable.Range(1, 5);
var list = ImmutableList.CreateRange<int>(numbers);

List of all immutable collection types:

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Functional Programming:
* Immutable collections

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
119 Functional Programming
127 Caching
135 Pointers
147 C# Script