Switch statement
• Syntax
Struct is used for integer type
The flag after case must be a constant at compile time.
The scaling parameter does not indicate the scaling of the range.
String DaySuffix (int days)
{
String result = "th ";
If (days/10! = 1)
Switch (days % 10)
{
Case 1:
Result = "st"; break;
Case 2:
Result = "nd"; break;
Case 3:
Result = "rd"; break;
Default: // indicates that the preceding conditions are not met.
Result = "th"; break;
}
Return result;
}
You can only use the switch statement for custom types of integer, string, or can be implicitly converted to integer or string. The case flag must be a constant during compilation.
In C #, the Is keyword in Visual Basic Is not compared in case, for example:
Switch (expression ())
{
Case Is <42: // error www.2cto.com
Case method (): // Error
}
No range comparison operator in C.
Switch (expression ())
{
Case 16 To 21: // Error
Case 16 .. 21: // Error
}
Note: Each case segment must contain a break statement, and the default statement is no exception.
Author: ershouyage