Wednesday 26 December 2012

The Underlying Type of an Enum

Enums in C# are generally backed by the underlying type int (actually System.Int32). This is a signed value ranging from -2 billion to positive 2 billion (a little over, actually, 2.147 billion).  However, this underlying type can be overridden e.g. enum Selection : sbyte. Now the enum is a signed 8 bit integer (ranging from -128 to 127). Note, however, that the base type of Selection is System.Enum and not sbyte! Forget what you know about base type specification!

No comments: