1

I am looking for a way to cast an int to an Enum, e.g.

var result = (MyEnum)value;

The Problem is that i only have the Integer and a System.Type.

And this doesn't work:

var result = (type)value;

Thanks for your help.

Sukram
  • 456
  • 3
  • 16

1 Answers1

1

You can use:

 Enum.ToObject(type, value);

Although I have no idea how you expect to use that result if you don't know what the type is at compile time.

Servy
  • 202,030
  • 26
  • 332
  • 449