當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Array.Clone方法代碼示例

本文整理匯總了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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:52,代碼來源:Array.Clone

輸出:

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
開發者ID:VB程序員,項目名稱:System,代碼行數:19,代碼來源:Array.Clone


注:本文中的System.Array.Clone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。