I got an arraylist of rectangles and I want to edit the X & Y values of all of them.
I tried using a foreach loop
foreach (Rectangle rect in rectangles)
rect.X += 1;
But this wouldn't work as it's read-only, so I tried a regular for loop
for (int i = 0; i < rectangles.Count; i++)
rectangles[i].X += 1;
And for some reason this wouldn't work either, because rectangles[i] just doesn't have any of rectangle's methods.
Then I stumbled across a post somewhere on stackoverflow about how to call methods of elements of an arraylist. And I haven't been able to find examples of this, so I hope someone can clear this up.
(Unit.unitArray[selectedUnit] as MyClass).DisplayUnitAttributes()
But I have no idea how to put this to use, I don't understand what Unit is supposed to be replaced with, and I'm guessing MyClass would be Rectangle...
Any help is appreciated!
TLDR: I want to iterate over an arraylist with rectangles, and edit the X & Y values of them.