ArrayList.CopyTo copies the entire ArrayList to a compatible one-dimensional Array, starting at the beginning of the target array.
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
Public Class SamplesArrayList
Public Shared Sub Main()
Dim mySourceList As New ArrayList()
mySourceList.Add("A")
mySourceList.Add("B")
mySourceList.Add("C")
mySourceList.Add("D")
mySourceList.Add("E")
mySourceList.Add("F")
Dim myTargetArray(14) As String
myTargetArray(0) = "AA"
myTargetArray(1) = "BB"
myTargetArray(2) = "CC"
myTargetArray(3) = "DD"
myTargetArray(4) = "EE"
myTargetArray(5) = "FF"
myTargetArray(6) = "GG"
myTargetArray(7) = "HH"
myTargetArray(8) = "II"
PrintValues(myTargetArray, " "c)
mySourceList.CopyTo(1, myTargetArray, 7, 1)
PrintValues(myTargetArray, " "c)
mySourceList.CopyTo(myTargetArray, 6)
PrintValues(myTargetArray, " "c)
mySourceList.CopyTo(myTargetArray)
PrintValues(myTargetArray, " "c)
End Sub
Public Shared Sub PrintValues(myArr() As String, mySeparator As Char)
Dim i As Integer
For i = 0 To myArr.Length - 1
Console.Write("{0}{1}", mySeparator, myArr(i))
Next i
Console.WriteLine()
End Sub
End Class
Related examples in the same category