I have a class as follows -
public class Student
{
string name {get; set;}
int age {get; set;}
}
I can access properties by -
Student s = new Student();
var age = s.age;
But what if I want to access properties by doing something like this -
Student s = new Student();
string property = "age";
var value = s.property
And this should return age. The property I want to access is decided at runtime.
Also, I would be interested in knowing the reverse assignment. That is, instead of -
s.age = 25;
Something like
string property = "age";
s.property = 35;