ArrayList

The ArrayList is a collection class that models a dynamic array, whose size increases as required when new objects are added to the array. The items in the array are Object instances, which means that you can use instances of this class to hold any type of variable.

The ArrayList implements the IList, ICollection, and ICloneable interfaces. Let's look first at a simple example of how to use it:

Sub Main()
   Dim a As ArrayList = New ArrayList()

   a.Add("Joe")
   a.Add("Jane")
   a.Add("Jim")

   Dim i As Integer
   For i = 0 To a.Count - 1
      Console.Out.WriteLine(a.Item(i))
   Next
End Sub

First you create the ArrayList a using the regular object variable declaration and initialization. Then you use the Add method (from IList) to add three literal strings ...

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.