4
Reply

Use value from one list to another list

Ask a question
Steve Tsiki

Steve Tsiki

13y
1.5k
1
Greetings guys.

I would like to create 2 lists, in which the first one should contain rectangles and the other some kind of objects.

For example:

List<Rectangles> recs = new List<Rectangle>();
List<Object> objs = new List<Object>(); // Object is an example of a class that I have created and named Object
Rectangle rec;
Object obj;

if (something)
{
        rec = new Rectangle(x,y,width,height);
        recs.Add(rec);
        obj = new Object(/* I want this field to be the value of the rectangle previously crearted*/,                 Content.Load<Texture2D>("myImage.jpeg"));
        objs.Add(obj);
}

Any suggestions? Thanks in advance.

Answers (4)