We discussed the
if single-selection statement and the
else double-selection statement in Chapter 5. C# provides the switch multiple-selection statement to perform different actions based on the possible values of an expression. Each action is associated with the value of a constant integral expression or a constant string expression that the variable or expression on which the
switch is based may assume. A constant integral expression is any expression involving character and integer constants that evaluates to an integer value—i.e., values of type
char, or a constant from an
enum type (
enum is discussed in Section 7.10). A constant string expression ...