本文整理汇总了VB.NET中System.Collections.Hashtable.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Hashtable.CopyTo方法的具体用法?VB.NET Hashtable.CopyTo怎么用?VB.NET Hashtable.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.CopyTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: SamplesHashtable
' 导入命名空间
Imports System.Collections
Public Class SamplesHashtable
Public Shared Sub Main()
' Creates and initializes the source Hashtable.
Dim mySourceHT As New Hashtable()
mySourceHT.Add("A", "valueA")
mySourceHT.Add("B", "valueB")
' Creates and initializes the one-dimensional target Array.
Dim myTargetArray(14) As String
myTargetArray(0) = "The"
myTargetArray(1) = "quick"
myTargetArray(2) = "brown"
myTargetArray(3) = "fox"
myTargetArray(4) = "jumps"
myTargetArray(5) = "over"
myTargetArray(6) = "the"
myTargetArray(7) = "lazy"
myTargetArray(8) = "dog"
' Displays the values of the target Array.
Console.WriteLine("The target Array contains the following before:")
PrintValues(myTargetArray, " "c)
' Copies the keys in the source Hashtable to the target Hashtable, starting at index 6.
Console.WriteLine("After copying the keys, starting at index 6:")
mySourceHT.Keys.CopyTo(myTargetArray, 6)
' Displays the values of the target Array.
PrintValues(myTargetArray, " "c)
' Copies the values in the source Hashtable to the target Hashtable, starting at index 6.
Console.WriteLine("After copying the values, starting at index 6:")
mySourceHT.Values.CopyTo(myTargetArray, 6)
' Displays the values of the target Array.
PrintValues(myTargetArray, " "c)
End Sub
Public Shared Sub PrintValues(myArr As String(), mySeparator As Char)
For i As Integer = 0 To myArr.Length - 1
Console.Write($"{mySeparator}{myArr(i)}")
Next i
Console.WriteLine()
End Sub
End Class
输出:
The target Array contains the following before: The quick brown fox jumps over the lazy dog After copying the keys, starting at index 6: The quick brown fox jumps over A B dog After copying the values, starting at index 6: The quick brown fox jumps over valueA valueB dog