枚举的各种操作

循环枚举,得到枚举的列表值:

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();

 

posted @ 2024-07-11 08:49  木子zzgxl  阅读(1)  评论(0编辑  收藏  举报