Code often has to dispatch to certain logic based on an enum value. One of the best candidate statements to carry out this task is the
switch statement. In fact, the code editor in Visual Studio has a handy feature for generating a full
switch statement for all of an enum’s members. Here’s the way to do it: Given a variable of an enum type, type switch and press Tab twice. Now enter the variable name and press Enter. For our
Color type, this technique is illustrated in Figure 11.10.
Although it might seem tempting to get rid of the default branch, this isn’t ...