Is there a way to refer to a property name with a variable?
Scenario: Object A have public integer property X an Z, so...
public void setProperty(in
Not in the way your suggesting, but yes it is doable. You could use a dynamic
object (or even just an object with a property indexer) e.g.
string property = index == 1 ? "X" : "Z";
A[property] = value;
Or alternatively by using Reflection:
string property = index == 1 ? "X" : "Z";
return A.GetType().GetProperty(property).SetValue(A, value);