A switch is a statement that is very similar to an if statement. However, a switch allows a condition to have multiple values.
The basic structure of the program is as follows
Switch (textval)
{
Case Val:
Program code
Break
Case VAL2:
Program code
Break
Case VAL3:
Program code
Break
......
Case VALN:
Program code
Break
}
A switch is a statement that consists of curly braces, which contain case and break in parentheses.
Where C # requires that a case must have a break. A case cannot jump directly to the next case.
Break means to jump out, when the value of the case conforms to the switch condition value, enters into the value of the suit and executes the code, executes the break, jumps out of the switch statement, and executes other program code. There can be countless case, the machine is not tired anyway.
Flowchart arrows to the right are eligible and do not conform downward.
The code is a bit of a brain remnant, but the meaning is right. Simple, clear.
intA = -, B = One; Switch(A +b) { Case Ten: Console.WriteLine ("correct"); Break; Case -: Console.WriteLine ("correct"); Break; Case Panax Notoginseng: Console.WriteLine ("correct"); Break; }
There is a keyword in switch, default. The code within the default is executed without a matching case value in switch. The code is as follows:
intA = -, B = One; Switch(A +b) { Case Ten: Console.WriteLine ("correct"); Break; Case -: Console.WriteLine ("correct"); Break; Case -: Console.WriteLine ("correct"); Break; default: Console.WriteLine ("None of them are right."); Break; }
Okay, so that's the switch base.
C#_ judgment [switch statement]:[c# get started classic]