Class MapBuilder<TK, TV>
- Namespace
- Map
- Assembly
- Map.dll
The MapBuilder is a mutable helper for creating an immutable Map. It's more efficient to add items to this builder first and then convert it to a Map in one go, rather than creating a new Map for each addition.
public sealed class MapBuilder<TK, TV>
Type Parameters
TKTV
- Inheritance
-
MapBuilder<TK, TV>
- Inherited Members
Constructors
MapBuilder(IEqualityComparer<TK>?, int)
Creates a new MapBuilder. You can optionally provide a custom comparer for keys and an initial capacity.
public MapBuilder(IEqualityComparer<TK>? comparer = null, int initialCapacity = 16)
Parameters
comparerIEqualityComparer<TK>initialCapacityint
Methods
Add(TK, TV)
Adds a key-value pair to the builder. If the internal array is full, it will be resized.
public void Add(TK key, TV value)
Parameters
keyTKvalueTV
ToImmutable()
Converts the builder's contents into an immutable Map. This is the main "build" step.
public Map<TK, TV> ToImmutable()
Returns
- Map<TK, TV>