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:

image

You’ll see this colon “derives from” syntax recurring quite a bit in Chapter 14 when we discuss inheritance. Permitted underlying ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.