I have an enum type with some discontinued values for each enum. When I try to cast an int value to the enum type it returns with multiple enum values seperated with the | operator. Can anyone explain this logic of how it is cast?
enum EnumTest { Test1 = 0, Test2 = 1, Test3 = 1 << 1, Test4 = 1 << 2, Test5 = 1 << 12, Test6 = 1 << 13, Test7 = 1 << 20, Test8 = 1 << 22, Test9 = 1 << 23, Test10 = 1 << 24, Test11 = 1 << 25, Test12 = 1 << 14, Test13 = 1 << 15, Test14 = 1 << 16, Test15 = 1 << 25, Test16 = 1 << 17, Test17 = 1 << 18, Test18 = 1 << 19, Test19 = 1 << 21, Test20 = 1 << 26 } public void method1() { int number=67239937; EnumTest e = (EnumTest)number; //output: Test2|Test16|Test20 }
ehas the value67239937under the covers. The actual mapping to the enum tags is of no concern to the compiler -- enums are really just dolled up integers. It's when the value is interpreted by other pieces of code that the tags come into play.