January 2011
Intermediate to advanced
1648 pages
70h 30m
English
switch StatementCode 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.
Figure 11.10. Generating a switch statement for an enum.

Although it might seem tempting to get rid of the default branch, this isn’t ...
Read now
Unlock full access