Hashtable.CopyTo Method copies the Hashtable elements to a one-dimensional Array instance at the specified index.
Imports System
Imports System.Collections
Public Class SamplesHashtable
Public Shared Sub Main()
Dim mySourceHT As New Hashtable()
mySourceHT.Add("A", "valueA")
mySourceHT.Add("B", "valueB")
Dim myTargetArray(14) As String
myTargetArray(0) = "The"
myTargetArray(1) = "quick"
myTargetArray(2) = "brown"
myTargetArray(3) = "fox"
PrintValues(myTargetArray)
mySourceHT.Keys.CopyTo(myTargetArray, 6)
PrintValues(myTargetArray)
mySourceHT.Values.CopyTo(myTargetArray, 6)
PrintValues(myTargetArray)
End Sub 'Main
Public Shared Sub PrintValues(myArr() As String)
Dim i As Integer
For i = 0 To myArr.Length - 1
Console.WriteLine("{0}", myArr(i))
Next i
End Sub
End Class
Related examples in the same category