This is very cheap - it is effectively non-op, indeed, if enum has the base int type to start with (which is the default). For example, here is an example program:
using System; enum Foo { A, B, C }; class Test { static void Main() { Foo x = Foo.B; int y = (int) x; } }
And the generated code for Main (not optimized):
.method private hidebysig static void Main() cil managed { .entrypoint
The drop effect is used for the compiler - the data in memory is already in the corresponding state, so you just need to copy the value as if it were copying int to int .
If the base enumeration type is not int , then converting the enum to int has the same effect as casting the base type to int . For example, if the base type is long , you will get something like conv.i4 in the same way that you usually do long before int .
source share