© { JSL }
30
Text Box: Using Arrays
Using Arrays
·all array access is bounds checked
wthrows IndexOutOfRangeException
w
Folded Corner:
class Example
{
    static void Use(int[,] grid)
    {  
        int rowLength = grid.GetLength(0);
        int colLength = grid.GetLength(1);
        for (int row = 0; row != rowLength; row++)
        {
            for (int col = 0; col != colLength; col++)
            {
                Console.WriteLine(grid[row,col]);
            }
        }
    }
    static void Main()
    {  
        Use(new int[,]{ {1,2,3}, {4,5,6} });
        ...
    }
}
there is no direct way to make rowLength constant