How to get the length of row/column of multidimensional array in C#?

Muhammad Faisal picture Muhammad Faisal · Feb 23, 2012 · Viewed 86k times · Source

How do I get the length of a row or column of a multidimensional array in C#?

for example:

int[,] matrix = new int[2,3];

matrix.rowLength = 2;
matrix.colLength = 3;

Answer

mindandmedia picture mindandmedia · Feb 23, 2012
matrix.GetLength(0)  -> Gets the first dimension size

matrix.GetLength(1)  -> Gets the second dimension size