How do I access a row of a 2-dimensional array in C#? I want to get the count of row i.
Thanks!
How do I access a row of a 2-dimensional array in C#? I want to get the count of row i.
Thanks!
The question really depends on what type of 2D array you are thinking about and what dimension your row is.
Proper 2D array
// Init
var arr = new int[5,10];
// Counts
arr.GetLength(0) // Length of first dimension: 5
arr.GetLength(1) // Length of second dimension: 10
Jagged "2D" array
// Init
var arr = new int[3][];
// Initially arr[0],arr[1],arr[2] is null, so we have to intialize them:
arr[0] = new int[5];
arr[1] = new int[4];
arr[2] = new int[2];
// Counts
arr.Length // Length of first dimension
// In this case the "second dimension" (if you can call it that) is of variable size
arr[0].Length // Length: 5
arr[1].Length // Length: 4
arr[2].Length // Length: 2