471,318 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

C# Question

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

I hope this makes sense.

Thanks,

Yosh
Jul 21 '05 #1
3 1030
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!
***************************

"Yosh" wrote:
What is the best way to convert an integer to a Enum value?

I hope this makes sense.

Thanks,

Yosh

Jul 21 '05 #2
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.

"Yosh" wrote:
What is the best way to convert an integer to a Enum value?

I hope this makes sense.

Thanks,

Yosh

Jul 21 '05 #3
if Color is an enum then:

Color c = (Color)1234;

"Yosh" <Yo**@nospam.com> schrieb im Newsbeitrag
news:#6**************@tk2msftngp13.phx.gbl...
What is the best way to convert an integer to a Enum value?

I hope this makes sense.

Thanks,

Yosh

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mohammed Mazid | last post: by
3 posts views Thread by Stevey | last post: by
10 posts views Thread by glenn | last post: by
53 posts views Thread by Jeff | last post: by
56 posts views Thread by spibou | last post: by
2 posts views Thread by Allan Ebdrup | last post: by
3 posts views Thread by Zhang Weiwu | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.