C# Tutorials - Herong's Tutorial Examples - v3.32, by Herong Yang
"switch" Statements
This section describes 'switch' statements - controlling expressions with multiple embedded statement blocks. At run time, only one statement blocks will be executed depending on the value of the controlling expression.
A "switch" statement switches the flow of execution to one of the pre-defined sections of statement depending on the resulting value of the controlling expression. Here is the syntax of a "switch" statement:
switch statement: switch (expression) { case literal_1: embedded_statements break; case literal_2: embedded_statements break; ...... default: embedded_statements break; }
When a "switch" statement is encountered in the execution flow, the expression will be evaluated first. If resulting value equals to one of the literals listed in the "case" clauses, the execution flow will be switched to the first embedded statement of that "case" clause. The "break" statement will break the execution flow from continuing to the next statement, and transfer it to the end of the "switch" statement.
If the resulting value of the expression does no equal to any of the literals listed in the "case" clauses, the execution flow will be switched to the first embedded statement of the "default" clause.
Table of Contents
►Logical Expressions and Conditional Statements
Visual C# 2010 Express Edition
C# Compiler and Intermediate Language
Compiling C# Source Code Files
MSBuild - Microsoft Build Engine
System.Diagnostics.FileVersionInfo Class
WPF - Windows Presentation Foundation