How to find the number of horizontal rows in a 2D array ?
I have :
Dim i(,) As Integer = {{2, 5, 6, 7}, {32, 5, 4, 2}}
Find the number of rows in i ?
For example :
// Here, array i has 2 sets of data i.e. 2 rows
// set1 = {2,5,6,7} and set2 = {32,5,4,2}
// So, I want the number of sets i.e 2 in this case !
Please help !
We use arrayname. length to determine the number of rows in a 2D array because the length of a 2D array is equal to the number of rows it has. The number of columns may vary row to row, which is why the number of rows is used as the length of the 2D array.
The number of elements in a 2D array is the number of rows times the number of columns. The code below creates a 2D array with 2 rows and 3 columns named ticketInfo and a 2D array with 3 rows and 2 columns named seatingChart .
The length of a 2D array is the number of rows it has. The row index runs from 0 to length-1. Each row of a 2D array can have a different number of cells, so each row has its own length : uneven[0] refers to row 0 of the array, uneven[1] refers to row 1, and so on.
On the exam assume that any 2 dimensional (2D) array is in row-major order. The outer array can be thought of as the rows and the inner arrays the columns.
The GetLength method can be used to find out the length of any dimension of the array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With