Hi,
We have a simple class 'Person' below. public class Person { public string FirstName(){...} public int Age() {...} public string Address() {...} } Code Block
We can get the name of the Person class at runtime by
Code Block
Type type = typeof(Person);
string clsName = type.Name;
Console.writeline(clsName);
If we want to get the Age property name at runtime, we should get its PropertyInfo first. The code looks like
Code Block
Type type = typeof(Person);
PropertyInfo prop = type.GetProperty("Age");
string ageName = prop.Name;
Console.writeline(propName);
It is strange that we want the name but we should pass the name string in first.
So, is it possible that we can get the name of Age property without having to pass a string in?
Any help is appreciated.