O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Underlying Types

Because we’ve mentioned the word constant quite a bit, you might be wondering where enum members get their values. Moreover, what’s the type of those constant values? To answer those questions, we must introduce the notion of an underlying type that’s associated with an enum’s definition. The underlying type indicates the domain for the constants declared within the enum. If left unspecified, an enum’s underlying type is a 32-bit integer. You can specify the underlying type explicitly as shown here:

enum Color : long{    Red,    Green,    Blue,}

You’ll see this colon “derives from” syntax recurring quite a bit in Chapter 14 when we discuss inheritance. Permitted underlying types are integral numeric types such as byte, short, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required