Share via


Capacity Property

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overridable Property Capacity As Integer
public virtual int Capacity { get; set; }
public:
virtual property int Capacity {
    int get ();
    void set (int value);
}
abstract Capacity : int with get, set
override Capacity : int with get, set
function get Capacity () : int
function set Capacity (value : int)

Property Value

Type: System. . :: . .Int32
The number of elements that the ArrayList can contain.

Remarks

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

Capacity is always greater than or equal to Count. 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.

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

.NET Framework Security

See Also

Reference

ArrayList Class

System.Collections Namespace