Dictionary<TKey,TValue>.TrimExcess Dictionary<TKey,TValue>.TrimExcess Dictionary<TKey,TValue>.TrimExcess Dictionary<TKey,TValue>.TrimExcess Method

定義

多載

TrimExcess(Int32) TrimExcess(Int32) TrimExcess(Int32) 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() TrimExcess() TrimExcess() TrimExcess()

將此字典容量設定為一開始若使用所有項目初始化的應有容量。Sets the capacity of this dictionary to what it would be if it had been originally initialized with all its entries.

TrimExcess(Int32) TrimExcess(Int32) TrimExcess(Int32) TrimExcess(Int32)

將此字典容量設定為最多可以保留的指定項目數量,但不必進一步擴充其支援儲存體。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)

參數

capacity
Int32 Int32 Int32 Int32

新的容量。The new capacity.

例外狀況

備註

這個方法可以用來在已知不會新增任何新專案的情況下,將記憶體額外負荷降到最低。This method can be used to minimize the memory overhead once it is known that no new elements will be added.

TrimExcess() TrimExcess() TrimExcess() TrimExcess()

將此字典容量設定為一開始若使用所有項目初始化的應有容量。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 ()

備註

這個方法可以用來將記憶體額外負荷降到最低,一旦知道不會將任何新專案加入字典中。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();

適用於