有没有一种方法可以将一个属性的引用存储到一个变量中,使我能够像访问该对象的属性一样访问它,就像这样:
如果是这样,我该怎么做呢?
编辑:为了更清晰一些,这就是正在发生的事情:
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.
}
我希望这能帮助你更好地帮助我...