当前位置: 首页>>代码示例>>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;未经允许,请勿转载。