SortedList.Capacity 属性

定义

获取或设置 SortedList 对象的容量。Gets or sets the capacity of a SortedList object.

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

属性值

SortedList 对象可包含的元素数。The number of elements that the SortedList object can contain.

异常

分配的值小于 SortedList 对象中的当前元素数。The value assigned is less than the current number of elements in the SortedList object.

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

注解

CapacitySortedList 对象可存储的元素数。Capacity is the number of elements that the SortedList object can store. Count 是实际处于 SortedList中的元素的数目。Count is the number of elements that are actually in the SortedList.

Capacity 始终大于或等于 CountCapacity is always greater than or equal to Count. 如果在添加元素时 Count 超过 Capacity,则在复制旧元素并添加新元素之前,重新分配内部数组,将自动增加容量。If Count exceeds Capacity while adding elements, the capacity is automatically increased by reallocating the internal array before copying the old elements and adding the new elements.

可以通过调用 TrimToSize 或显式设置 Capacity 属性来减少容量。The capacity can be decreased by calling TrimToSize 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.

适用于

另请参阅