C# Question

  • Thread starter Thread starter Yosh
  • Start date Start date
Y

Yosh

What is the best way to convert an integer to a Enum value?

I hope this makes sense.

Thanks,

Yosh
 
You can reflect out the integral values of the enum and then assign, if this
has to be done dynamically. If not, write a switch case that turns numbers
into the enum value.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
public enum myenum : Int32
{
value1 = 123,
value2 = 567
}

Int32 x=123;
myenum v;

to convert x into enum

v = (myenum) x;

even if x does not correspond to values in the list, it will work.
 
Back
Top