asp.net C # switch statement usage

Source: Internet
Author: User
Tags case statement

Switch statement

This statement asks for the value of an expression and compares that value to many of the case. Each case is associated with a statement list called a switch block. C # executes a block of statements associated with a switch block that matches the value of an expression. When you try to find the value of a particular expression, the switch is an Easy-to-understand programming method that contains many If/else statement pairs.

An expression used as a switch statement drive is enclosed in parentheses followed by the Switch keyword. In general, the value of a switch statement expression must be one of the following types: sbyte, Byte, short, ushort, int, uint, long, ulong, char, string. You may also use an expression that can be implicitly converted to the above value type.

The switch block starts with a keyword case followed by a constant expression. A constant expression is followed by a colon, followed by a list of statements. Break will be a closing sentence block.

The value in Swith (value) is to be compared with the value after the case in the statement body, if the corresponding case value is the same, then execute the corresponding cases statement, as in this example because the value passed in is 1, so it is necessary to execute the first instance statement. The case statement within the switch body can have an infinite number, but the value cannot be duplicated, and this value is the one behind the case. Each case statement must be followed by a break that causes execution to jump out of the switch statement. If no case expression matches the switch value, control is passed to the statement following the optional default label. If there is no default label, control is passed outside of the switch. In addition to emphasize a bit of default is also to add a break, this can not be omitted

public static string Get_mcode_desc (String mcode)
{
Switch (Mcode)
{
Case "101000":
Return "link detection (network management)";

Case "101001":
Return "Business Front machine check-in transaction (sign on)";

Case "101002":
Return "Business front machine sign off transaction (sign off)";

Case "101010":
Return ' order relationship query ';

Case "101071":
Return "Child Application Status query (sub_application status)";

Case "101011":
Return "card issuing request (air, write card) (Create sub application request)";

Case "101012":
Return "The card Operation results notice (Card reader) (terminal cards operation result)";

Case "101021":
Return "business before the machine reported loss notice (Prehost Report of Loss)";

Case "101022":
Return "Suspend notice (cancel the loss)";

Case "101031":
Return "Cancellation request (air, write card) (cancellation request)";

Case "101032":
Return "Waste card request (annul)";

Case "101041":
Return "Personalized Information update request (AIR) (update sub_application)";

Case "101051":
Return "restore Enterprise initial master key (reload keys)";

Case "101061":
Return "Information service notification (message send)";

Case "101062":
Return "Information status query (message status)";

Case "101081":
Return "Machinery Status Data report (terminal status)";

Case "101091":
Return "the card operation request (Cards operation request)";

Case "102011":
Return "The air card operation result notice (air cards operation results)";

Case "102021":
Return "one card business front machine application Stop notice (prehost application stop)";

Case "102031":
Return "Information query request (message query requests)";

Case "102041":
Return "Notice of loss of service system (Servicesystem Report of Loss)";

Case
"108001":
Return "Enterprise Client query predecessor status (query Prehost status)";
}
Return "Unknown transaction code";
}
}

A switch statement is a Process Control statement that is very clearly used. And if statements are very similar, are based on a given condition to select the execution of statements do not understand, but the switch's conditional value is discrete, but can be a, B, C, such as the form, if statements can be continuous, such as >a, < B and so on.
Because there is no switch statement in the ASP tutorial but there is a similar Select Case statement, the switch statement mentioned here can only be in the ASP.net tutorial (C #), because it said, I love ASP and Asp.netswitch statements

Related Article

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.