Chapter 13. Enumerations

Enumerations

An enumeration, or enum, isa programmer-defined type, like a class or a struct.

  • Like structs, enumsare value types, and therefore store their data directly, rather than separately, with a reference and data.

  • Enums have only one typeof member: named constants with integral values.

The following code shows an example of the declaration of a new enum type called TrafficLight, which contains three members. Notice that the list of member declarations is a comma-separated list; there are no semicolons in an enum declaration.

Enumerations

Every enum type has an underlying integral type, which by default is int.

  • Each enum member is assigned ...

Get Illustrated C# 2008 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.