How do you get the width and height of a multi-dimensional array? How do you get the width and height of a multi-dimensional array? arrays arrays

How do you get the width and height of a multi-dimensional array?


You use Array.GetLength with the index of the dimension you wish to retrieve.


Use GetLength(), rather than Length.

int rowsOrHeight = ary.GetLength(0);int colsOrWidth = ary.GetLength(1);


// Two-dimensional GetLength example.int[,] two = new int[5, 10];Console.WriteLine(two.GetLength(0)); // Writes 5Console.WriteLine(two.GetLength(1)); // Writes 10