O'Reilly logo

A Programmer's Guide to C# 5.0, 4th Edition by Nick Wienholt, Eric Gunnerson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 20

image

Enumerations

Enumerations are useful when a value in the program can have only a specific set of values. An enumeration might be used where a control supports only four colors or for a network package that supports only two protocols.

A Line-Style Enumeration

In the following example, a line-drawing class uses an enumeration to declare the styles of lines it can draw:

using System;public class Draw{    public enum LineStyle    {       Solid,       Dotted,       DotDash,       // trailing comma is optional    }    public void DrawLine(int x1, int y1, int x2, int y2, LineStyle lineStyle)    {       switch (lineStyle)       {             ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required