Behind the Scenes

To wrap up our discussion about enums, let’s take a quick peek behind the scenes. Even though the use of the colon syntax to specify an underlying type makes it seem like the enum type derives from the underlying type, this is not the case. All enum types derive from the System.Enum base type that’s supplied by the runtime. Each member defined on the enum turns into a constant field. An instance of the enum contains a single field holding the value that’s being used. Figure 11.11 shows what an enum definition looks like in ILDASM.

Figure 11.11. Under the hood, an enum contains both instance and static members.

image

If you’re somehow ...

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.