for my new project I want my code to create a new rectangle for each one existing in a list.
Given is the List "particles". I want to do something like
foreach(Rectangle rec in particles){
Rectangle r2 = new Rectangle(10, 10, 10, 10);
particles.add(r2);
}
The problem is, that I need to define a name. If I don't know, how many rectangles will be in list particles when the code executes, I can't just do it like that (I hope you get what I mean). What I need is something like a function that creates a new rectangle with the name r3 or r4 or r5 (...) as long as there are new rectangles. I really don't know how. Can you help me?
Here's an example of using a Dictionary, as suggested by MiiinimalLogic: