SortedList<TKey,TValue>.Capacity 属性

定义

获取或设置 SortedList<TKey,TValue> 可包含的元素数。Gets or sets the number of elements that the SortedList<TKey,TValue> can contain.

public:
 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.

异常

Capacity 已设置为一个小于 Count 的值。Capacity is set to a value that is less than Count.

系统上没有足够的可用内存。There is not enough memory available on the system.

注解

CapacitySortedList<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.

适用于

另请参阅