How to Get Variables From List of Classes?


I have a list and it stores classes.

	public List<TreeData> treeDatabase = new List<TreeData> ();

The TreeData class has the following variables;

	public string name;
	public List<int> logX;
	public List<int> logY;
	public List<int> logZ;
	public List<int> leavesX;
	public List<int> leavesY;
	public List<int> leavesZ;

However, I’m not sure how I can retrieve the specific variables from an individual class within this list, (i.e, ‘name’, ‘logZ’, etc.).

If anybody is able to shed some light on this, I would greatly appreciate it!

Use Reflection. For questions like this, Stack Overflow is the place to go.

I think what you are looking for is something like this…
You access them just like you would an object in an array .

List<Vector3> list = new List<Vector3>();
    void Start () {
        list.Add(new Vector3(transform.position.x + 3, transform.position.y - 3));
        float Y = list[0].y;

Thank you guys for the help! Hexagonius provided me exactly what I needed “treeDatabase[0].logX[0]”. I had no idea a list can be used that conveniently, it really helped.

And again thank you dpoly and jtputz for the additional resources and advice.



foreach (var t in treeDatabase){
foreach (var l in leavesX){