This documentation is archived and is not being maintained.

ArrayList.Capacity Property

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

[Visual Basic]
Public Overridable Property Capacity As Integer
public virtual int Capacity {get; set;}
public: __property virtual int get_Capacity();
public: __property virtual void set_Capacity(int);
public function get Capacity() : int;
public function set Capacity(int);

Property Value

The number of elements that the ArrayList can contain.


Exception Type Condition
ArgumentOutOfRangeException Capacity is set to a value that is less than Count.


Capacity is the number of elements that the ArrayList is capable of storing. 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 of the list is doubled by automatically reallocating the internal array.

When the value of Capacity is set explicitly, the internal array is also reallocated to accommodate the specified capacity. If Capacity is explicitly set to zero, the common language runtime sets it to the default capacity instead. The default capacity is 16.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

ArrayList Class | ArrayList Members | System.Collections Namespace | Count