How to: Determine the Length of One Dimension of an Array
The GetLength method of an array returns the length along the dimension you specify.
To determine the length of one dimension of an array
Call GetLength on the array name. Supply the dimension for which you want the length as the argument to GetLength. Note that the dimension argument is 0-based.
Dim sampleTripleArray(,,) As Short = New Short(2, 3, 4) {} MsgBox("Dimension lengths of sampleTripleArray are " & CStr(sampleTripleArray.GetLength(0)) _ & ", " & CStr(sampleTripleArray.GetLength(1)) & ", " & CStr(sampleTripleArray.GetLength(2)))
The MsgBox call displays "Dimension lengths of sampleTripleArray are 3, 4, 5".
The lowest index value for each dimension is always 0, and the GetUpperBound method returns a dimension's highest index value. For each dimension, GetLength returns a value higher by 1 than that returned by GetUpperBound. As with GetLength, the dimension you specify for GetUpperBound is 0-based.
You can find the total length of an array from its Length property.
You can change the overall size by changing the length of an individual dimension. However, you cannot change the rank (the number of dimensions).
See Also
Tasks
How to: Declare an Array Variable
How to: Initialize an Array Variable
How to: Determine the Size of an Array
How to: Change the Size of an Array