I misunderstood the question for the first time, my bad.
You can do this with Reflection:
public int Method(Bar bar, string propertyName) { var prop = typeof(Bar).GetProperty(propertyName); int value = (int)prop.GetValue(bar,null); return value * 2; }
Then you call it like this:
Method(bar,"A");
Just noticed that in your example, the three variables in Bar are public instance variables. I assume that you just did it for your sample, but if it is really so in your real class, use the Rex M approach.
Bfree source share