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