O'Reilly logo

C# Primer Plus by Klaus Michelsen

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

Enumerated Constants

Recall the discussion from the previous chapter about constants and the advantages of representing a single constant number like 3.1415… with the name Pi. Sometimes, we need to represent a finite set of related constants all known prior to the compilation of the program. Examples could be the days of the week { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} or the months of the year { January, February, March, and so on} . Enumerators are useful for creating symbolic constants representing those values.

For example, if you want to represent the five colors just mentioned, you can declare Color to be an enumeration with the five colors Green, Blue, Red, Yellow and Purple. In C#, you express this with the following ...

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