枚举字段应用

 1 // 声明
 2 public   enum  DefaultType :  int
 3 {
 4       布料 = 1,
 5       商标 = 2,
 6       钢弓 = 4,
 7       棉碗 = 8
 8}

 9 // 绑定到comboBox
10 comboBox3.DataSource  = Enum.GetValues( typeof (Dal.Class1.DefaultType));
11 // 取得comboBox选定值
12 private   void  comboBox3_Leave( object  sender, EventArgs e)
13          {
14            Dal.Class1.DefaultType msa;
15            msa = (Dal.Class1.DefaultType)Enum.Parse(typeof(Dal.Class1.DefaultType),comboBox3.SelectedItem.ToString());
16            Dal.Class1.DefaultType type = msa;
17           int intType = (int)type;
18           MessageBox.Show(intType.ToString());
19        }

你可能感兴趣的:(枚举字段应用)