Record the usage of switch case, switchcase
We usually like to use it when making multiple conditions.
Switch (expression)
{
Case: constant 1
Expression 1;
Break;
Case: constant 2
Expression 2;
Break;
Case: constant 3
Expression 3;
Break;
....
Default: constant 4
Expression 4;
Break;
}
Here are some notes for you:
1. Only constants rather than variables can be contained in case;
2. in C #, a switch part is not allowed to be executed to the next switch part. That is to say, break must be added for each case part or a statement that can prevent the case from being executed to the next case, for example:
Case: constant 3
Expression 3;
Break;
Or
Case: constant n
While (true)
Expression n;
Yes.
It is ensured that the switch will not continue to go to the next switch;
3. default can be dispensable. When all cases are not satisfied, the expression in default will be executed;