Enumerations are a handy programming construct that allow you to group name/value pairs. For
example, assume you are creating a video game application that allows the player to select one of three
character categories (Wizard, Fighter, or Thief). Rather than keeping track of simple numerical values to
represent each possibility, you could build a custom enumeration using the enum keyword.
// A C# enumeration type.
enum CharacterType
{
Wizard = 100,
Fighter = 200,
Thief = 300
}
By default, the storage used to hold each item is a 32-bit integer; however, it is possible to alter this
storage slot if need be (e.g., when programming for a low-memory device such as a Windows mobile
device). Also, the CTS demands that enumerated types derive from a common base class, System.Enum.
As you will see in Chapter 4, this base class defines a number of interesting members that allow you to
extract, manipulate, and transform the underlying name/value pairs programmatically.
No comments:
Post a Comment