本文整理汇总了VB.NET中System.Array.Clone方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Array.Clone方法的具体用法?VB.NET Array.Clone怎么用?VB.NET Array.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: SamplesArray
' 导入命名空间
Imports System.Globalization
Public Class SamplesArray
Public Shared Sub Main()
' Create and initialize a new CultureInfo array.
Dim ci0 As New CultureInfo("ar-SA", False)
Dim ci1 As New CultureInfo("en-US", False)
Dim ci2 As New CultureInfo("fr-FR", False)
Dim ci3 As New CultureInfo("ja-JP", False)
Dim arrCI() As CultureInfo = {ci0, ci1, ci2, ci3}
' Create a clone of the CultureInfo array.
Dim arrCIClone As CultureInfo() = CType(arrCI.Clone(), CultureInfo())
' Replace an element in the clone array.
Dim ci4 As New CultureInfo("th-TH", False)
arrCIClone(0) = ci4
' Display the contents of the original array.
Console.WriteLine("The original array contains the following values:")
PrintIndexAndValues(arrCI)
' Display the contents of the clone array.
Console.WriteLine("The clone array contains the following values:")
PrintIndexAndValues(arrCIClone)
' Display the DateTimeFormatInfo.DateSeparator for the fourth element in both arrays.
Console.WriteLine("Before changes to the clone:")
Console.WriteLine(" Original: The DateTimeFormatInfo.DateSeparator for {0} is {1}.", arrCI(3).Name, arrCI(3).DateTimeFormat.DateSeparator)
Console.WriteLine(" Clone: The DateTimeFormatInfo.DateSeparator for {0} is {1}.", arrCIClone(3).Name, arrCIClone(3).DateTimeFormat.DateSeparator)
' Replace the DateTimeFormatInfo.DateSeparator for the fourth element in the clone array.
arrCIClone(3).DateTimeFormat.DateSeparator = "-"
' Display the DateTimeFormatInfo.DateSeparator for the fourth element in both arrays.
Console.WriteLine("After changes to the clone:")
Console.WriteLine(" Original: The DateTimeFormatInfo.DateSeparator for {0} is {1}.", arrCI(3).Name, arrCI(3).DateTimeFormat.DateSeparator)
Console.WriteLine(" Clone: The DateTimeFormatInfo.DateSeparator for {0} is {1}.", arrCIClone(3).Name, arrCIClone(3).DateTimeFormat.DateSeparator)
End Sub
Public Shared Sub PrintIndexAndValues(myArray As Array)
Dim i As Integer
For i = myArray.GetLowerBound(0) To myArray.GetUpperBound(0)
Console.WriteLine(vbTab + "[{0}]:" + vbTab + "{1}", i, myArray.GetValue(i))
Next i
End Sub
End Class
输出:
The original array contains the following values: [0]: ar-SA [1]: en-US [2]: fr-FR [3]: ja-JP The clone array contains the following values: [0]: th-TH [1]: en-US [2]: fr-FR [3]: ja-JP Before changes to the clone: Original: The DateTimeFormatInfo.DateSeparator for ja-JP is /. Clone: The DateTimeFormatInfo.DateSeparator for ja-JP is /. After changes to the clone: Original: The DateTimeFormatInfo.DateSeparator for ja-JP is -. Clone: The DateTimeFormatInfo.DateSeparator for ja-JP is -.
示例2: Tester
Public Class Tester
Public Shared Sub Main
Dim arrayA() As String = {"One", "Two", "Three", "Four", "Five", "Six"}
Console.WriteLine(Join(arrayA, ","))
Dim arrayB() As String = {"A", "B", "C", "D", "E", "E", "F", "G", "H"}
Console.WriteLine(Join(arrayB, ","))
' ----- Make a reference copy.
Dim arrayC() As String = arrayA
Console.WriteLine(Join(arrayC, ","))
' ----- Make a full, unique copy of all elements.
Dim arrayD() As String = arrayA.Clone
Console.WriteLine(Join(arrayD, ","))
End Sub
End Class