System.Collections.Generic.SortedList<TKey,TValue>.Capacity Property

Gets or sets the number of elements that the SortedList`2 can contain.


public int Capacity { get; set; }


Documentation for this section has not yet been entered.


SortedList`2.Capacity is the number of elements that the SortedList`2 can store. SortedList`2.Count is the number of elements that are actually in the SortedList`2.

SortedList`2.Capacity is always greater than or equal to SortedList`2.Count. If SortedList`2.Count exceeds SortedList`2.Capacity while adding elements, the capacity is increased by automatically reallocating the internal array before copying the old elements and adding the new elements.

The capacity can be decreased by calling SortedList`2.TrimExcess or by setting the SortedList`2.Capacity property explicitly. When the value of SortedList`2.Capacity is set explicitly, the internal array is also reallocated to accommodate the specified capacity.

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.


Namespace: System.Collections.Generic
Assembly: System (in System.dll)
Assembly Versions:,
Since: .NET 2.0