简体   繁体   中英

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

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();
    }

}

为什么不

Matrix.GetLength(0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM