ArrayList: Add

Add

Adds a new item to the end of the list.



 Public Function Add(
	  ByRef Value As Variant ) As Long

Parameters

Value
[ByRef] Variant. The item to be added to the list.

Return Values

Long -  The index at which the item was added.

Remarks

As items are added, the capacity is increased as necessary. The items are appended to the end of the list and maintain the order they were added, provided no other method is used to change the order, such as Insert or Remove.

Exceptions

Exception TypeCondition
NotSupportedExceptionThe ArrayList is Read-Only
- or -
The ArrayList is Fixed-Size.

Example

In the following example, several items are added to an ArrayListobject and then iterated over, displaying the items in the list.
Private Sub Main()    Dim list As New ArrayList        ' add several elements to the ArrayList    list.Add "Humpty"    list.Add "Dumpty"    list.Add "sat"    list.Add "on"    list.Add "a"    list.Add "wall."        '' Display the contents of the ArrayList    PrintValues list        '' Wait for user to press return key    Console.ReadLine    End SubPrivate Sub PrintValues(ByVal en As IEnumerable)    Const Space As String = " "        Dim value As Variant        '' Iterate over the list    For Each value In en        '' Write each value onto the same line        Console.WriteValue value        Console.WriteValue Space    Next valueEnd Sub'' This code produces the following output.'''' Humpty Dumpty sat on a wall.
The items are added to the list, then a For..Each statement is usedto iterate over the list, displaying the name in the Console window.

See Also

Project VBCorLib Overview Class ArrayList Overview ArrayList Properties ArrayList Methods AddRange