Skip to main content
Format.
Source Link
Mateen Ulhaq
  • 27.8k
  • 21
  • 121
  • 155

Just cast it:

MyEnum e = (MyEnum)3;

You can checkCheck if it's in range using Enum.IsDefinedEnum.IsDefined:

if (Enum.IsDefined(typeof(MyEnum), 3)) { ... }

Just cast it:

MyEnum e = (MyEnum)3;

You can check if it's in range using Enum.IsDefined:

if (Enum.IsDefined(typeof(MyEnum), 3)) { ... }

Just cast it:

MyEnum e = (MyEnum)3;

Check if it's in range using Enum.IsDefined:

if (Enum.IsDefined(typeof(MyEnum), 3)) { ... }
Source Link
Matt Hamilton
  • 204.9k
  • 61
  • 395
  • 321

Just cast it:

MyEnum e = (MyEnum)3;

You can check if it's in range using Enum.IsDefined:

if (Enum.IsDefined(typeof(MyEnum), 3)) { ... }