Successfully added
C#
by Michael
C# Switch
C# Switch Statements
Use the switch statement to select one of many code blocks to be executed.
switch(expression)
{
case a:
// code block
break;
case b:
// code block
break;
default:
// code block
break;
}
This is how it works:
- The
switchexpression is evaluated once - The value of the expression is compared with the values of each
case - If there is a match, the associated block of code is executed
- The
breakanddefaultkeywords will be described later in this chapter
Referenced in:
Comments