本文整理匯總了VB.NET中System.Array.GetLength方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Array.GetLength方法的具體用法?VB.NET Array.GetLength怎麽用?VB.NET Array.GetLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Array
的用法示例。
在下文中一共展示了Array.GetLength方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: SamplesArray
Public Class SamplesArray
Public Shared Sub Main()
' make a single dimension array
Dim MyArray1 As Array = Array.CreateInstance(GetType(Integer), 5)
' make a 3 dimensional array
Dim MyArray2 As Array = Array.CreateInstance(GetType(Integer), 5, 3, 2)
' make an array container
Dim BossArray As Array = Array.CreateInstance(GetType(Array), 2)
BossArray.SetValue(MyArray1, 0)
BossArray.SetValue(MyArray2, 1)
Dim i As Integer = 0
Dim j As Integer
Dim rank As Integer
For Each anArray As Array In BossArray
rank = anArray.Rank
If rank > 1
Console.WriteLine("Lengths of {0:d} dimension array[{1:d}]", rank, i)
' show the lengths of each dimension
For j = 0 To rank - 1
Console.WriteLine(" Length of dimension({0:d}) = {1:d}", j, anArray.GetLength(j))
Next j
Else
Console.WriteLine("Lengths of single dimension array[{0:d}]", i)
End If
' show the total length of the entire array or all dimensions
Console.WriteLine(" Total length of the array = {0:d}", anArray.Length)
Console.WriteLine()
i = i + 1
Next anArray
End Sub
End Class
輸出:
Lengths of single dimension array[0] Total length of the array = 5 Lengths of 3 dimension array[1] Length of dimension(0) = 5 Length of dimension(1) = 3 Length of dimension(2) = 2 Total length of the array = 30