Reserves are supported by integral types and behave like them (mostly).
Unfortunately, this means that you can assign any value that is valid for the base type to an enumeration - the check is not performed.
In the case of default initialization, this will be the default value for the base type, which is 0
for integral types.
You can also do this and compile and run:
var value = (Test)43;
Perhaps redefine your listing as follows:
public enum Test { None = 0, One = 1, Two = 2 }
The Enum
class has several convenient methods for working with enumerations - for example, IsDefined
, to find out if a variable contains a specific enumeration value.
Odded source share