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


VB.NET Array.Length屬性代碼示例

本文整理匯總了VB.NET中System.Array.Length屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET Array.Length屬性的具體用法?VB.NET Array.Length怎麽用?VB.NET Array.Length使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在System.Array的用法示例。


在下文中一共展示了Array.Length屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

Module Example
    Public Sub Main()
        ' Declare a single-dimensional string array
        Dim array1d() As String = {"zero", "one", "two", "three"}
        ShowArrayInfo(array1d)

        ' Declare a two-dimensional string array
        Dim array2d(,) As String = {{"zero", "0"}, {"one", "1"},
                                     {"two", "2"}, {"three", "3"},
                                     {"four", "4"}, {"five", "5"}}
        ShowArrayInfo(array2d)

        ' Declare a three-dimensional integer array  
        Dim array3d(,,) As Integer = New Integer(,,) {{{1, 2, 3}, {4, 5, 6}},
                                        {{7, 8, 9}, {10, 11, 12}}}
        ShowArrayInfo(array3d)

    End Sub

    Private Sub ShowArrayInfo(arr As Array)
        Console.WriteLine("Length of Array:      {0,3}", arr.Length)
        Console.WriteLine("Number of Dimensions: {0,3}", arr.Rank)
        ' For multidimensional arrays, show number of elements in each dimension.
        If arr.Rank > 1 Then
            For dimension As Integer = 1 To arr.Rank
                Console.WriteLine("   Dimension {0}: {1,3}", dimension,
                                  arr.GetUpperBound(dimension - 1) + 1)
            Next
        End If
        Console.WriteLine()
    End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:32,代碼來源:Array.Length

輸出:

Length of Array:        4
Number of Dimensions:   1

Length of Array:       12
Number of Dimensions:   2
Dimension 1:   6
Dimension 2:   2

Length of Array:       12
Number of Dimensions:   3
Dimension 1:   2
Dimension 2:   2
Dimension 3:   3

示例2: Tester

Module Tester

   Sub Main()
      Dim i As Integer

      Dim array As Integer()    ' declare array variable
      array = New Integer(9) {} ' allocate memory for array

      Console.WriteLine("Subscript " & vbTab & "Value")

      For i = 0 To array.GetUpperBound(0)
         Console.WriteLine( i & vbTab & array(i))
      Next

      Console.WriteLine("The array contains " & _
         array.Length & " elements.")

   End Sub 
   
End Module
開發者ID:VB程序員,項目名稱:System,代碼行數:20,代碼來源:Array.Length


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