Two Dimension Array Length
-
:)Hi everyone :) Could you please help me? I would like to know the length of Two Dimension Array. Example : Dim arr(2)() as string Dim LenRank2 as Integer Dim i as int32 For i=0 to 10 arr(1)(i)=i.ToString arr(2)(i)=i.ToString Next LenRank2 = arr.GetLength(1) I got the error message "Index was outside the bounds of the array." I want to get the length of second dimension. What's wrong? Thank in advance. !alien!
-
:)Hi everyone :) Could you please help me? I would like to know the length of Two Dimension Array. Example : Dim arr(2)() as string Dim LenRank2 as Integer Dim i as int32 For i=0 to 10 arr(1)(i)=i.ToString arr(2)(i)=i.ToString Next LenRank2 = arr.GetLength(1) I got the error message "Index was outside the bounds of the array." I want to get the length of second dimension. What's wrong? Thank in advance. !alien!
The error message is because of the first dimension. In VB: If you declare as arr(2), the index will start from 0. ie. arr(0) and arr(1) If you want to use arr(1) and arr(2), declare as arr(1 to 2)
-
The error message is because of the first dimension. In VB: If you declare as arr(2), the index will start from 0. ie. arr(0) and arr(1) If you want to use arr(1) and arr(2), declare as arr(1 to 2)
Thank you for your reply. :) Have a nice day. !alien!
-
:)Hi everyone :) Could you please help me? I would like to know the length of Two Dimension Array. Example : Dim arr(2)() as string Dim LenRank2 as Integer Dim i as int32 For i=0 to 10 arr(1)(i)=i.ToString arr(2)(i)=i.ToString Next LenRank2 = arr.GetLength(1) I got the error message "Index was outside the bounds of the array." I want to get the length of second dimension. What's wrong? Thank in advance. !alien!
You can get the length of the inner arrays by calling Length(). Just like how you would do it with the outer array.
Dim myArray()() As Integer = {New Integer() {1, 2, 3, 4}, _
New Integer() {1, 2}, _
New Integer() {1}}
For index As Integer = 0 To (myArray.Length - 1) Step 1
MessageBox.Show(myArray(index).Length.ToString)
NextThe output above will be "4", "2", and "1".