我有两个循环,我想保存在一个数组中的数据。第一个for循环将在数组中创建5个矩形。之后,第二个for循环将创建5个矩形并将它们添加到数组中。但有些东西不起作用。我在代码的最后一行得到了“索引超出了数组边界”的错误消息,我不知道该怎么改变。如何将两个for循环的数据保存在一个数组中?
int framewidth = texture.Width/sourceRects.Length;
int frameheight = texture.Height;
private void vorrück(Rectangle[] sourceRects, int framewidth, int frameheight)
{
int doublelenght = sourceRects.Length * 2;
for (int i = 0; i < sourceRects.Length; i++)
sourceRects[i] = new Rectangle(i * framewidth, 0, framewidth, frameheight);
for (int normallenght = sourceRects.Length; normallenght < doublelenght; normallenght++)
sourceRects[normallenght] = new Rectangle((sourceRects.Length - 1 - normallenght) * framewidth, 0, framewidth, frameheight);
}