I have property
public Enums.CustomEnumProp MyEnum { get; set; }
which is of type CustomEnumProp
public enum CustomEnumProp { A = 1, B = 2, C = 3}
and I need to use passed int value as a user selection and assign it to the MyEnum property.
forexampe: is user is selected 2 from combobox then assign this int to the MyEnum.
Thanks
Just cast the int to the enum.
o.MyEnum = (CustomEnumProp) myInt;
You can also use the Enum.IsDefined method to check that the int is valid.
if (Enum.IsDefined(typeof(CustomEnumProp), myInt))
o.MyEnum = (CustomEnumProp) myInt;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With