Enumeration

An enumeration is a set of discrete and related values. You would use an enumeration if you wanted to create a variable that is limited to a set of values, such as one that represents months or one that includes a list of flags. Enumerations expand into a type where the members of the enumeration are defined as constants. The default underlying type of an enumeration is integer. An enumeration is never required; an integer variable can be used directly instead. However, enumerations are safer and more extensible than integer variables, and they enhance readability. In the following sample code, the Months.GetMonth method outputs the name of a month. The method relies on integer values:

public class Months { static public void GetMonth(int ...

Get Programming Microsoft® Visual C#® 2008: The Language 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.