How to save data of two for loops in one array?
- by Homer_Simpson
I have two for loops and I wanna save that data in one array. The first for loop will create 5 rectangles in the array. After that, the second for loop will create 5 rectangles and add them to the array. But something doesn't work. I get that "Index was outside the bounds of the array" error message in the last line of the code and I don't know what to change.
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);
}