System.Collections.CollectionBase.Capacity Property

Gets or sets the number of elements that the CollectionBase can contain.

Syntax

[System.Runtime.InteropServices.ComVisible(false)]
public int Capacity { get; set; }

Value

Documentation for this section has not yet been entered.

Remarks

CollectionBase.Capacity is the number of elements that the CollectionBase can store. CollectionBase.Count is the number of elements that are actually in the CollectionBase.

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

The capacity can be decreased by setting the CollectionBase.Capacity property explicitly. When the value of CollectionBase.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.

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0