I am looking for a solution to solve this problem I have.
I got an Object:
- Person (String ID, String FirstName, String LastName)
I got a List with a couple Persons
- List<Person> persons;
What my goal is:
1. Iterate through List
2. Get property value from that element with a string named to that property
For example:
I want to know the ID of the person in a list:
I can do this:
foreach(Person p in persons)
{
String personId = p.ID;
}
But I want to do something like this:
foreach(Person p in persons)
{
String personId = p. + "ID";
}
I want to append the string "ID"
to get the ID of that element, instead of calling p.ID
.
Is this possible? I need a solution for this, and I have spent a lot of time but couldn't find any solution on the internet.