Switch is a control statement that selects a block of statements to execute.
A switch statement includes one or more statement blocks that are executed. Each statement block includes one or more case labels, followed by the statement to be executed.
As the following code
CodeintParms=1;Switch(parms) { Case0: Case1:console.writeline ("Case 0 or 1"); Break; Case2:console.writeline ("Case 2"); Break; Case7-4: Console.WriteLine ("Case 4-7"); Break;default: Console.WriteLine ("Default case Default"); Break; }
Note:
Each case label specifies a constant value. The switch statement transfers control to the toggle portion of the case label that matches the value of the switch expression. If any case label does not contain a matching value, the control is transferred to the default section, if any. If there is no default part, no action is taken and the control is transferred outside of the switch statement.
A switch statement can contain any number of switch sections, each of which can have one or more case labels. However, any two case labels cannot contain the same constant value.
When you execute a list of statements in the selected switches section, the first statement is executed first, and then the entire statement list is executed, usually until a jump statement is reached, such as break, Goto case, return, or throw. At this point, the control is transferred outside of the switch statement or transferred to another case label.
C # switch Case statement