An Intermezzo About Enums

Related to constants are enums, which are value types that contain for their members a set of named constants. A typical example of an enum is Color, as shown here:

enum Color{    Red,    Green,    Blue,}

Right inside the framework you can find quite a few enums, as well; for example, to indicate a “file open mode” when using System.IO application programming interfaces (APIs). Just like other value types, you can apply an access modifier to the type.

Note: (Trailing) Commas

Notice that an enum’s members are comma separated and not semicolon separated. Basically, they denote a list of symbolic values. A trailing comma is allowed after the last member, which is often put there so that the addition of new members to ...

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