| 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 Type | Condition |
|---|---|
| NotSupportedException | The ArrayList is Read-Only - or - The ArrayList is Fixed-Size. |
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 Sub
Private 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 value
End 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 used
to iterate over the list, displaying the name in the Console window.