This documentation is archived and is not being maintained.

List(T).Add Method

Adds an object to the end of the List(T).

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

abstract Add : 
        item:'T -> unit 
override Add : 
        item:'T -> unit 


Type: T
The object to be added to the end of the List(T). The value can be a null reference (Nothing in Visual Basic) for reference types.



List(T) accepts a null reference (Nothing in Visual Basic) as a valid value for reference types and allows duplicate elements.

If Count already equals Capacity, the capacity of the List(T) 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 Count is less than 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 Count.

The following code example demonstrates several properties and methods of the List(T) generic class, including the Add method. The default constructor is used to create a list of strings with a capacity of 0. The Capacity property is displayed, and then the Add method is used to add several items. The items are listed, and the Capacity property is displayed again, along with the Count property, to show that the capacity has been increased as needed.

Other properties and methods are used to search for, insert, and remove elements from the list, and finally to clear the list.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.