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.

Image

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

If you’re somehow ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.