Switch statement usage Summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.