有没有办法将一个属性的引用存储到一个变量中,让我可以像访问该对象属性一样访问它,如下所示:
var ReferenceVariable = Object.Property;
ReferenceVariable = "SOMETHING";
If (Object.Property == "SOMETHING")
//It worked! Yaay!
如果是这样,我该怎么做?
编辑:为了清楚起见,这就是发生的事情:
private void UpdateColor(){
if (radioButton1.Checked){
Object.Color1 = Color.Red
}
if (radioButton2.Checked){
Object.Color2 = Color.Blue
}
.
.
.
if (radioButtonN.Checked){
Object.ColorN = Color.ColorN
}
}
这是非常次优的。理想情况下,该问题将在单选按钮更改时触发的函数中处理,因此它类似于...
private void RadioButton_CheckChanged(object sender, eventargs e){
//Something is done here to tell the program that we are interested in Object.Color...Whatever
}
private void UpdateColor(){
//Now we know what color we're looking at, we can just do it in one step rather than looking at a thousand (I exaggerate of course) radio buttons checked states.
}
我希望这能帮助你更多地帮助我......