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.

2 Answers 2

6

See the i in your j-loop

for (int j = 0; j < map.GetLength(1); j++)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you!And that proves that it was a silly question, thank you again!
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] = '.';
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.