I'm trying to dynamically get all the values of a specific property from all class instances. I've managed to do it with one property
public class fighter
{
public string Name { get; set; }
public double Height { get; set; }
}
fighter[] roster[5] = new fighter();
string namearray = roster.Select(x => x.Name).ToArray();
int weightarray = roster.Select(x => x.Weight).ToArray();
However I want to reference the property with a variable and put it in a loop so I don't need a select function for every property. Is there anyway to do this, or any other method to get all values of a property from all objects where this could work?
Aucun commentaire:
Enregistrer un commentaire