You can use reflection . For example, if the PropertyName is a public property on MyClass , and you have an instance of this class, you could:
MyClass myClassInstance = ... double temp = (double)typeof(MyClass).GetProperty("PropertyName").GetValue(myClassInstance, null);
If this is a public field :
MyClass myClassInstance = ... double temp = (double)typeof(MyClass).GetField("FieldName").GetValue(myClassInstance);
Of course, you must understand that thinking is not exempt from costs. There may be a penalty for performance compared to direct access to properties / fields.
Darin Dimitrov
source share