【发布时间】:2016-03-12 13:37:22
【问题描述】:
我用这个矩形阵列碰壁了。简单的一维数组我很好,但是一个有 4 列的数组我刚刚开始把头撞在墙上......
我已将数组定义为:
private Rectangle[,] brick = new Rectangle[2, 8];
然后将这些与那个结合使用:
int[,] brickLocation = { {0, 0}, {0,21}, {0,42}, {0, 63}, {0, 84}, {0, 105}, {0, 126},
{61, 0}, {61,21}, {61,42}, {61, 63}, {61, 84}, {61, 105}, {61, 126} };
bool[] brickLive = { true, true, true, true, true, true, true,
true, true, true, true, true, true, true };
然后尝试通过多数组循环绘制矩形:
for (int i = 0; i < brickLive.Length; i++)
{
for (int j = 0; j < brickLive.Length; i++)
{
if (brickLive[i] == true)
{
brick[i, j] = new Rectangle(brickLocation[i, 0], brickLocation[i, 1], brkLength, brkHeight);
brickPaper.DrawRectangle(brickPen, brick[i, j]);
}
else
{
continue; //move onto next brick
}
}
}
它停止工作了,我想不出我能做什么....有人可以帮忙吗?
【问题讨论】:
-
它究竟是如何“停止工作”的?是否有一些错误消息或行为是否意外?
-
我得到了以下行的 IndexOutOfRangeException:brick[i, j] = new Rectangle(brickLocation[i, 0],brickLocation[i, 1], brkLength, brkHeight);
-
你的 j for 循环中有 i++
-
哦,我做到了,但还是不行。
标签: c# arrays multidimensional-array