SortedList<TKey,TValue>.TrimExcess 方法

定義

如果該數目小於目前容量的 90%,則將容量設為 SortedList<TKey,TValue> 中項目的實際數目。

public:
 void TrimExcess();
public void TrimExcess ();
member this.TrimExcess : unit -> unit
Public Sub TrimExcess ()

備註

如果集合中不會新增任何新元素,這個方法可用來將集合的記憶體額外負荷降到最低。 不過,重新配置和複製大型 SortedList<TKey,TValue> 的成本可能相當龐大,因此 TrimExcess ,如果清單超過 90% 的容量,則方法不會執行任何動作。 這可避免產生相當小的收益的大型重新配置成本。

這個方法是 O (n) 作業,其中 nCount

若要將 重設為 SortedList<TKey,TValue> 其初始狀態,請在呼叫 TrimExcess 方法之前先呼叫 Clear 方法。 修剪空白 SortedList<TKey,TValue> 會將 的 SortedList<TKey,TValue> 容量設定為預設容量。

您也可以使用 Capacity 屬性來設定容量。

適用於

另請參閱