C
coltrane
I am just learning c# and I have a question regarding enums.
I have an enum with a underlying type of int
enum numbers : int {
one = 1,
two = 2,
three = 3
}
I then try to assign an enum item to an integer:
int x = numbers.one;
I get the following error:
Cannot implicitly convert type 'FunWithEnums.Program.numbers' to
'int'. An explicit conversion exists (are you missing a cast?)
I thought that if I set the underlying class to int I would not have
to cast.
If I still have to cast the enum then what is the point of setting the
underlying type
thanks for the help
john
I have an enum with a underlying type of int
enum numbers : int {
one = 1,
two = 2,
three = 3
}
I then try to assign an enum item to an integer:
int x = numbers.one;
I get the following error:
Cannot implicitly convert type 'FunWithEnums.Program.numbers' to
'int'. An explicit conversion exists (are you missing a cast?)
I thought that if I set the underlying class to int I would not have
to cast.
If I still have to cast the enum then what is the point of setting the
underlying type
thanks for the help
john