枚举的各种操作
循环枚举,得到枚举的列表值:
cbbItemFlag.DisplayMember = "Text"; cbbItemFlag.ValueMember = "Value"; foreach (CollectionItemFlagEnum flag in Enum.GetValues(typeof(CollectionItemFlagEnum))) { cbbItemFlag.Items.Add(new ValueStrText() { Value = flag.ToString(), Text = $"{flag.ToString()}-{flag.ToDescription()}" }); }
字符串转枚举对象:
(Parity)Enum.Parse(typeof(Parity), cbbParity.Text);
数字转枚举
item.TypeStr = ((CheckPointType)item.Type).ToDescription();