Michael Braun

Michael Braun

  • NA
  • 0
  • 22.6k

Accessing member variables of a list

Jul 6 2009 9:09 PM
Hey everyone, I've been wondering about this, but can't find anything about it.

Basically, I've got a class, and a list of that class:

public class Person
{
    public Rectangle boundingBox;
    public int health;
}

List personList = new List();


And I've got a function that takes a list of rectangles:

private void CheckBoundingBoxes(List boundingBoxes)
{
    // Do stuff...
}


Now, is it possible that instead of doing this to generate a list of rectangles based on each persons bounding box:

List boundingBoxList = new List(personList.Count);

for (int i = 0; i < personList.Count; ++i)
{
    boundingBoxList.Add(personList[i].boundingBox);
}

CheckBoundingBoxes(boundingBoxList);


I can just access the bounding box variable directly, something like:

CheckBoundingBoxes(new List( personList { boundingBox } ) );

to do the same thing?

I appreciate any help I get in regards to this :)

Answers (1)