假设我有以下内容:

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

PrintMatrix(int[,] Matrix)函数中,如何求多维数组只有一维的长度?
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)

关于c# - 仅查找多维数组中第一维的长度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2032283/

10-09 22:41