仅查找多维数组中第一个维的长度

时间:2010-01-09 03:50:00

标签: c# .net arrays

假设我有以下内容:

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

}

1 个答案:

答案 0 :(得分:14)

为什么不

Matrix.GetLength(0)