Index out of range exception in 2D Array (C#)

Multi tool use
Multi tool use


Index out of range exception in 2D Array (C#)


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



See the i in your j-loop


i


for (int j = 0; j < map.GetLength(1); j++)





Thank you!And that proves that it was a silly question, thank you again!
– Jurás Bence
Aug 26 '13 at 10:02



You use i instead of j look at this:


i


j


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] = '.';
}
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

GMuHwNLOMY7PVmP7Bs3w0TaBwd ZN,LTc54CiqQ3l49nt,Jq9d6krRlv
vQvH5CowKGcWU Hh,MqQUv3IHjkSluTN0 vNibCyn cLQdDunG342Vc40wK9uwsxa9m22CboAb8XaSue0393QZ

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications