C # judgment
The judgment structure requires the programmer to specify one or more conditions to be evaluated or tested, as well as statements to be executed if the condition is true (required) and statements to be executed if the condition is false (optional).
The following is a general form of a typical judgment structure in most programming languages:
Judgment sentence
C # provides the following types of judgment statements. Click the link to see the details of each statement.
Statement |
Description |
---|---|
If statement |
An if statement consists of a Boolean expression followed by one or more statements. |
If…else statement |
An if statement can be followed by an optional else statement, and the else statement is executed when the Boolean expression is false. |
Nested if statement |
You can use another if or else if statement within one if or else if statement. |
Switch statement |
A switch statement allows you to test when a variable is equal to multiple values. |
Nested switch statement |
You can use another switch statement within another switch statement. |
?
:
Operator
We have explained the conditional operator in the previous chapter ?
:
, which can be used instead of the if…else statement. Its general form is as follows:
Exp1 ? Exp2 : Exp3;
Among them Exp1
、 Exp2
and Exp3
is an expression. Please notethe use and location of colons.
?
value of the expression is determined by the Exp1
. It was decided. If Exp1
is true, calculate Exp2
. The result is the entire ?
value of the expression. If Exp1
is false, it is calculated Exp3
, the result is the entire ?
value of the expression.