enum Season { spring, summer, fall, winter }
int a = (int)Season.spring;
Is this a unboxing or just a normal casting? If this is a unboxing, could you explain why? I thought this is just a normal casting because 'enum' and 'int' is both a value-type data.
As documented in ECMA-334 11.3.3, C# defines a conversion to and from an
enumtype and its underlying type:However, this does not specify whether or not it is an unboxing conversion. That could be deduced, though, from the fact that both the enum and the integer are value-types, therefore no unboxing is involved.
ECMA-335, which defines the CLR, makes it more clear that an
enumis not just convertible to an integer, it actually is the integer, there is no conversion done at all: