This is my enum:
public enum DocumentTypes { [EnumMember] TYPE_1 = 1, [EnumMember] TYPE_2 = 2, [EnumMember] TYPE_3 = 3, [EnumMember] TYPE_4 = 4, [EnumMember] TYPE_5 = 5, [EnumMember] TYPE_6 = 6, [EnumMember] TYPE_7 = 7, [EnumMember] TYPE_8 = 12 }
If I want to obtain 'TYPE_8', if I only have 12, is there a way to get the enum value?
I tried this:
((DocumentTypes[])(Enum.GetValues(typeof(DocumentTypes))))[Convert.ToInt32("3")].ToString()
which returns a value of 'TYPE_4'
You can directly cast it:
int value = 12; DocumentTypes dt = (DocumentTypes)value;
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