简体   繁体   English

2D数组中的索引超出范围异常(C#)

[英]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. 我只是想让map [i,j]的所有元素成为一个点,但总是当我尝试运行它时,编译器会说:索引超出范围异常。 Maybe it's a stupid question but I had to ask it. 也许这是一个愚蠢的问题,但我不得不问它。

在j循环中查看i

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM