Chapter 10
Creating Lists of Items with Enumerations
IN THIS CHAPTER
Finding real-world examples of enumerations
Creating and using enumerations
Using enumerations to define flags
Using enumerations as parts of switches
To enumerate means to specify individual items, as in a list. For example, you might create an enumeration of colors and then list individual colors, such as red, blue, green, and so on. Using enumerations in programming makes sense because you can list individual items as part of a common collection. For example, Colors.Blue
would indicate the color blue, and Colors.Red
would indicate the color red. Because enumerations are so handy, you see them used all the time in the actual world, which is why you also see them in applications. Code should model the real world to provide useful functionality in an easy-to-understand form.
The enum
keyword lets you create enumerations in C#. This chapter begins by discussing basic enum
usage but then moves on to some interesting additions you can make. For example, you can use initializers to determine the initial value of each ...
Get C# 10.0 All-in-One For Dummies 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.