5
char[,] map = new char[10, 20];

for (int i = 0; i < map.GetLength(0); i++)
{
    for (int j = 0; i < map.GetLength(1); j++)
        map[i, j] = '.';
}

I just simply want to make all the elements of map[i,j] to be a point , but always when I try to run it the compiler says: Index out of range exception. Maybe it's a stupid question but I had to ask it.

AustinWBryan
  • 3,249
  • 3
  • 24
  • 42

2 Answers2

6

See the i in your j-loop

for (int j = 0; j < map.GetLength(1); j++)
I4V
  • 34,891
  • 6
  • 67
  • 79
4

You use i instead of j look at this:

char[,] map = new char[10, 20];

for (int i = 0; i < map.GetLength(0); i++)
{
    for (int j = 0; j < map.GetLength(1); j++)
    {
        map[i, j] = '.';
    }
}
AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
Alessandro D'Andria
  • 8,663
  • 2
  • 36
  • 32