Dictionary<TKey,TValue>.TrimExcess Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
TrimExcess(Int32) |
Sets the capacity of this dictionary to hold up a specified number of entries without any further expansion of its backing storage. |
TrimExcess() |
Sets the capacity of this dictionary to what it would be if it had been originally initialized with all its entries. |
TrimExcess(Int32)
- Source:
- Dictionary.cs
- Source:
- Dictionary.cs
- Source:
- Dictionary.cs
Sets the capacity of this dictionary to hold up a specified number of entries without any further expansion of its backing storage.
public:
void TrimExcess(int capacity);
public void TrimExcess (int capacity);
member this.TrimExcess : int -> unit
Public Sub TrimExcess (capacity As Integer)
Parameters
- capacity
- Int32
The new capacity.
Exceptions
capacity
is less than Count.
Remarks
This method can be used to minimize the memory overhead once it is known that no new elements will be added.
Applies to
TrimExcess()
- Source:
- Dictionary.cs
- Source:
- Dictionary.cs
- Source:
- Dictionary.cs
Sets the capacity of this dictionary to what it would be if it had been originally initialized with all its entries.
public:
void TrimExcess();
public void TrimExcess ();
member this.TrimExcess : unit -> unit
Public Sub TrimExcess ()
Remarks
This method can be used to minimize memory overhead once it is known that no new elements will be added to the dictionary. To allocate a minimum size storage array, execute the following statements:
dictionary.Clear();
dictionary.TrimExcess();