我需要帮助将选定的Enum值从Combobox(cbShowVal)传递到另一个类。
class A{
//Enum:
public enum myDisplayOptions{Test1, Test2, Test3}
//Combox binding:
cbShowVal.DataSource = Enum.GetValues(typeof(DisplayOptions));
}
class B{
private int newVal = 0;
public int GetNumOfSeats(myDisplayOptions ch){
swith(ch)
{
case myDisplayOptions.Test1:
newVal = 100;
break;
case myDisplayOptions.Test2:
newVal = 200;
break;
case myDisplayOptions.Test3:
newVal = 300;
break;
}
return newVal;
}
}
答案 0 :(得分:1)
将字符串转换回枚举
myDisplayOptions option =
(myDisplayOptions)Enum.Parse(typeof(myDisplayOptions), cbShowVal.SelectedValue);
然后
B b = new B();
int seats = b.GetNumOfSeats(option);