ArrayList: Add |
Adds a new item to the end of the list.
Public Function Add( ByRef Value As Variant ) As Long
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.
Exception | Condition |
---|---|
NotSupportedException |
The ArrayList is read-only -or- The ArrayList is fixed-size. |
In the following example, several items are added to an ArrayList object 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 End Sub Private Sub PrintValues(ByVal Source As IEnumerable) Dim Value As Variant ' Iterate over the list For Each Value In Source ' Write each value onto the same line Debug.Print Value; " "; Next End Sub ' This example produces the following output. ' ' Humpty Dumpty sat on a wall.