SortedList<TKey,TValue>.Capacity SortedList<TKey,TValue>.Capacity SortedList<TKey,TValue>.Capacity SortedList<TKey,TValue>.Capacity Property


取得或設定 SortedList<TKey,TValue> 可包含的項目數目。Gets or sets the number of elements that the SortedList<TKey,TValue> can contain.

 property int Capacity { int get(); void set(int value); };
public int Capacity { get; set; }
member this.Capacity : int with get, set
Public Property Capacity As Integer


SortedList<TKey,TValue> 可包含的項目數。The number of elements that the SortedList<TKey,TValue> can contain.


系統上沒有足夠的記憶體可用。There is not enough memory available on the system.


Capacity這是SortedList<TKey,TValue>可以儲存的專案數。Capacity is the number of elements that the SortedList<TKey,TValue> can store. Count這是實際在中SortedList<TKey,TValue>的元素數目。Count is the number of elements that are actually in the SortedList<TKey,TValue>.

Capacity一律大於或等於CountCapacity is always greater than or equal to Count. 如果CountCapacity加入專案時超過, 則會在複製舊專案並新增新專案之前, 先自動重新配置內部陣列, 以增加容量。If Count exceeds Capacity while adding elements, the capacity is increased by automatically reallocating the internal array before copying the old elements and adding the new elements.

您可以藉由呼叫TrimExcess或明確Capacity設定屬性來降低容量。The capacity can be decreased by calling TrimExcess or by setting the Capacity property explicitly. 當明確設定的Capacity值時, 內部陣列也會重新配置以容納指定的容量。When the value of Capacity is set explicitly, the internal array is also reallocated to accommodate the specified capacity.

抓取這個屬性的值是 O (1) 運算;設定屬性是 O (n) 運算, 其中n是新的容量。Retrieving the value of this property is an O(1) operation; setting the property is an O(n) operation, where n is the new capacity.