Copies the elements of the ArrayList to a new array of the specified element type.
Imports System
Imports System.Collections
Public Class SamplesArrayList
Public Shared Sub Main()
Dim myAL As New ArrayList()
myAL.Add("A")
myAL.Add("B")
myAL.Add("C")
myAL.Add("D")
myAL.Add("E")
PrintIndexAndValues(myAL)
Dim myArr As String() = CType(myAL.ToArray(GetType(String)), String())
PrintIndexAndValues(myArr)
End Sub 'Main
Overloads Public Shared Sub PrintIndexAndValues(myList As ArrayList)
Dim i As Integer = 0
Dim o As [Object]
For Each o In myList
Console.WriteLine(" [{0}]: {1}", i, o)
i = i + 1
Next o
End Sub
Overloads Public Shared Sub PrintIndexAndValues(myArr() As String)
Dim i As Integer
For i = 0 To myArr.Length - 1
Console.WriteLine(" [{0}]: {1}", i, myArr(i))
Next i
Console.WriteLine()
End Sub
End Class
Related examples in the same category