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

定義

如果該數目小於目前容量的 90%,則將容量設為 SortedList<TKey,TValue> 中元素的實際數目。Sets the capacity to the actual number of elements in the SortedList<TKey,TValue>, if that number is less than 90 percent of current capacity.

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

備註

如果未將任何新專案加入至集合, 則可以使用這個方法來將集合的記憶體額外負荷降到最低。This method can be used to minimize a collection's memory overhead if no new elements will be added to the collection. 不過, 重新配置和複製大型SortedList<TKey,TValue>的成本可能很大, TrimExcess因此, 如果清單超過 90% 的容量, 方法就不會執行任何動作。The cost of reallocating and copying a large SortedList<TKey,TValue> can be considerable, however, so the TrimExcess method does nothing if the list is at more than 90 percent of capacity. 這可避免產生較小增益的大量重新分配成本。This avoids incurring a large reallocation cost for a relatively small gain.

這個方法是 O (n) 運算, 其中nCountThis method is an O(n) operation, where n is Count.

若要將SortedList<TKey,TValue>重設為其初始狀態, Clear請先呼叫TrimExcess方法, 再呼叫方法。To reset a SortedList<TKey,TValue> to its initial state, call the Clear method before calling TrimExcess method. 修剪空白SortedList<TKey,TValue>會將的容量SortedList<TKey,TValue>設定為預設容量。Trimming an empty SortedList<TKey,TValue> sets the capacity of the SortedList<TKey,TValue> to the default capacity.

容量也可以使用Capacity屬性來設定。The capacity can also be set using the Capacity property.

適用於

另請參閱