Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有财产
public Enums.CustomEnumProp MyEnum { get; set; }
这是 CustomEnumProp 类型
public enum CustomEnumProp { A = 1, B = 2, C = 3}
我需要使用传递的 int 值作为用户选择并将其分配给MyEnum属性。
MyEnum
forexampe: 是用户从组合框中选择了 2,然后将此 int 分配给 MyEnum。
谢谢
只需int将enum.
int
enum
o.MyEnum = (CustomEnumProp) myInt;
您还可以使用该Enum.IsDefined方法来检查int是否有效。
Enum.IsDefined
if (Enum.IsDefined(typeof(CustomEnumProp), myInt)) o.MyEnum = (CustomEnumProp) myInt;