Gets or sets the number of elements that the ArrayList can contain.
[Visual Basic] Overridable Public Property Capacity As Integer [C#] public int Capacity {virtual get; virtual set;} [C++] public: __property virtual int get_Capacity(); public: __property virtual void set_Capacity(int); [JScript] public function get Capacity() : int; public function set Capacity(int);
The number of elements that the ArrayList can contain.
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | Capacity is being 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.
ArrayList Class | ArrayList Members | System.Collections Namespace | Count