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