Rectanglar array
Rectanglar array uses comma to separate each dimension.
The following two dimensional array is 5 by 5.
int[,] intArray = new int[5,5];
We can use GetDimension method to get the length of each dimension.
using System;
class Program
{
static void Main(string[] args)
{
int[,] intArray = new int[3, 4];
Console.WriteLine(intArray.GetLength(0));
Console.WriteLine(intArray.GetLength(1));
for (int i = 0; i < intArray.GetLength(0); i++)
{
for (int j = 0; j < intArray.GetLength(1); j++)
{
intArray[i, j] = i + j;
}
}
for (int i = 0; i < intArray.GetLength(0); i++)
{
for (int j = 0; j < intArray.GetLength(1); j++)
{
Console.Write(intArray[i, j]);
}
Console.WriteLine();
}
}
}
The output:
3
4
0123
1234
2345