C#遍历enum类型

 

对于enum类型:

使用foreach遍历enum类型的元素并填充combox

foreach ( HatchStyle hs1 in Enum.GetValues(typeof(HatchStyle)))
 {
     comboBox1.Items.Add(hs1.ToString());
 }
From a string: YourEnum foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString);
From an int: YourEnum foo = (YourEnum)yourInt;
From number you can also: YourEnum foo = Enum.ToObject(typeof(YourEnum) , yourInt);
 
_cmbOriginType.SelectedIndex = (int)SnappingTypes.用户指定;

你可能感兴趣的:(enum)