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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top