Is it possible in .NET 3.5 to specify an enum type?

Posted by RoboShop on Stack Overflow See other posts from Stack Overflow or by RoboShop
Published on 2010-05-12T06:40:54Z Indexed on 2010/05/12 6:44 UTC
Read the original article Hit count: 267

Filed under:
|
|
|

I have a enumerator which map to a bunch of int

example

enum MyEnum {
Open = 1,
Closed = 2,
Exit = 4

}

I find though that when I want to assign this to an integer, I have to cast it first.

int myEnumNumber = **(int)** MyEnum.Open;

Is it possible to specify the type of an enum so that it is implicit that there is a integer assigned to any value within the enum? That way, I do not need to keep casting it to an int if I want to use it

thanks

© Stack Overflow or respective owner

Related posts about enums

Related posts about c#