C # switch Case statement

Source: Internet
Author: User

Switch is a control statement that selects a block of statements to execute.

A switch statement includes one or more statement blocks that are executed. Each statement block includes one or more case labels, followed by the statement to be executed.

As the following code

CodeintParms=1;Switch(parms) { Case0: Case1:console.writeline ("Case 0 or 1"); Break; Case2:console.writeline ("Case 2"); Break; Case7-4: Console.WriteLine ("Case 4-7"); Break;default: Console.WriteLine ("Default case Default"); Break; }

Note:

Each case label specifies a constant value. The switch statement transfers control to the toggle portion of the case label that matches the value of the switch expression. If any case label does not contain a matching value, the control is transferred to the default section, if any. If there is no default part, no action is taken and the control is transferred outside of the switch statement.

A switch statement can contain any number of switch sections, each of which can have one or more case labels. However, any two case labels cannot contain the same constant value.

When you execute a list of statements in the selected switches section, the first statement is executed first, and then the entire statement list is executed, usually until a jump statement is reached, such as break, Goto case, return, or throw. At this point, the control is transferred outside of the switch statement or transferred to another case label.

C # switch Case statement

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.