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(int index, int value)
{
string property = "";
if (index == 1)
{
// set the property X with 'value'
property = "X";
}
else
{
// set the property Z with 'value'
property = "Z";
}
A.{property} = value;
}
This is a silly example so please believe, I have an use for this.
See Question&Answers more detail:os