You must use reflection.
To get the property value on targetObject :
var value = targetObject.GetType().GetProperty(vari).GetValue(targetObject, null);
To get the value of a field, it looks like:
var value = targetObject.GetType().GetField(vari).GetValue(targetObject, null);
If the property / field is not public or inherited from the base class, you need to specify explicit BindingFlags in GetProperty or GetField .
source share