A frozen collection is a read-only collection built for data that will not change. Construction is slower than for regular, concurrent, or immutable collections, but read operations are optimized for maximum speed. section 13.4
Use the appropriate frozen type for the data shape:
- FrozenDictionary<TKey,TValue> provides a read-only counterpart to Dictionary<TKey,TValue>. section 13.4
- FrozenSet<T> provides a read-only counterpart to HashSet<T>. section 13.4
- Use ImmutableArray<T> when a frozen, list-like collection is needed; frozen queues and stacks are not provided. section 13.4
- Frozen collections cannot be modified and do not provide immutable-style methods for creating modified copies. section 13.4
Build a frozen set
Create ordinary data first, then convert it with the appropriate extension method: var data = new List<int> { 1, 2, 3, 4 }; var set = data.ToFrozenSet();
Choose a frozen collection when data is accessed frequently but almost never modified. Rebuilding one after frequent changes can cost more than its faster lookups save; unlike immutable collections, frozen collections are inherently thread safe. section 13.4.1 section 13.5
