Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the length of only the first dimension in a multi-dimension array

Tags:

arrays

c#

.net

Let's say I have the following:

public void MakeMatrix(int matrixLength)
{
    int[,] Matrix = new Matrix[matrixLength,matrixLength]
    PopulateMatrix(Matrix);
    PrintMatrix(Matrix);
}

In the PrintMatrix(int[,] Matrix) function, how to I find the length of only one dimension of the multi-dimension array?

public void PrintMatrix(int[,] Matrix)
{
    int intLength = // I don't know what to put here     <===================
    for (int k = 0; k < intLength ; k++)
    {
        for (int l = 0; l < intLength; l++)
        {
            Console.Write("{0,2} ", Matrix[k, l]);
        }
        Console.WriteLine();
    }

}
like image 984
Ben McCormack Avatar asked Jan 09 '10 03:01

Ben McCormack


1 Answers

Why not

Matrix.GetLength(0)
like image 196
Sparky Avatar answered Nov 15 '22 06:11

Sparky