|
|
C# supports a number of control statements including break, continue, goto, if, switch, return, and throw. They are more or less similar to their counterparts in C++. The switch statement is,
however, significantly different. We will explore this difference in this lesson.
The syntax of the switch statement is given as under:
switch (expression)
{
case constant-expression:
statements
jump statement
[default:
statements
jump statement
]
}
Kindly pay attention to the following:
As mentioned earlier, we can also use a string in the switch constant-expression. This is demonstrated with the help of the following example:
void func(string option){
switch (option)
{
case "label":
goto case "jump":
case "quit":
return;
case "jump":
case "unwind":
throw new Exception();
default:
break;
}
}
Next >>> Lesson No. 9: C# Properties
|
|