Possible Duplicate:
convert an enum to another type of enum
When casting between enums of different types, is it possibly to directly cast from one type to the other like so?
LicenseTypes type;
TypeOfLicense type2;
type2 = (TypeOfLicense)type;
Or is it necessary to cast the enum to an int first? The compiler doesn’t complain, but I want to make sure I’m not going to get some kind of funky casting exception at runtime.
This may seem like an odd thing to do, but both enums are identical in structure and value. Only the type names differ in this case.
Although its a duplicate and I have flagged it as well. You can do simple casting, beucase the underlying type is
int, you can do:Here
typewill hold value ‘0’;Suppose you have:
But if you try to Cast
TypeOfLicence.value5then the variabletypewill hold the int value2You can also look at this link for creating extension methods for conversion between enums. (Its the accepted answer of the similar question)