0
我正好碰到这个问题,我有2 RadioButton
在我的课,每个RadioButton
的值应该是由类文件读取枚举,App.Config中读取按钮枚举值
让说:
Enum Status {
Good,
Bad
}
我没有问题,从我Main
调用值,但是我试图把这个变成App.Config中像这样:
<add key="ClassRadioButton1Status" value="Good"/>
<add key="ClassRadioButton2Status" value="Bad"/>
,也是我创建了一个普通类我的app.config像这样:
public static string ClassRadioButton1Status= ConfigurationManager.AppSettings["ClassRadioButton1Status"];
public static string ClassRadioButton2Status= ConfigurationManager.AppSettings["ClassRadioButton2Status"];
现在我Main
里面,我想打电话给这个RadioButton
像这样从枚举赋值:
Public void processing(){
if (RadioButton.Checked == True){
// here i have to Assign the Value from Enum to This:
Class.eStatus =// how to do from here?!!!!!!
}
}
为什么你要在app.config和编译后的枚举中指定状态的值?你的问题真的是如何解析一个字符串值来获得枚举值?如果它然后查找Enum.Parse() – Matt
马特:你的建议是什么?怎么做?! –
您可以使用Enum.GetNames()来检索枚举值的名称(从而使您的app.config中的设置键变为冗余),并使用Enum.Parse()将字符串解析为枚举值。 – Matt