System.Collections.ArrayList.Add Method

Adds an object to the end of the ArrayList.

Syntax

public virtual int Add (object value)

Parameters

value
The object to be added to the end of the ArrayList. The value can be null.

Returns

The ArrayList index at which the value has been added.

Exceptions

TypeReason
NotSupportedExceptionThe current instance is read-only or has a fixed size.

Remarks

ArrayList accepts null as a valid value and allows duplicate elements.

If ArrayList.Count already equals ArrayList.Capacity, the capacity of the ArrayList is increased by automatically reallocating the internal array, and the existing elements are copied to the new array before the new element is added.

If ArrayList.Count is less than ArrayList.Capacity, this method is an O(1) operation. If the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is ArrayList.Count.

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0