C # provides a conditional operator that can replace a simple if...else structure. The syntax for this conditional operator is as follows:
Conditional expression? Branch 1: Branch 2
?: is the conditional operator, you can see that it has 3 operands, so it is called a ternary operator. Its arithmetic logic is: when the conditional expression is true, branch 1 is executed, and when the conditional expression is false, branch 2 is executed.
In the following example, depending on the age, the output is "adult" or "minor":
Static void Main (string[] args) { int; Age string backup; Note backup = Age >=?" Adult ":" minors "; Console.WriteLine (Backup);}
Because of age=17, the value of the conditional expression Age>=18 is false, which returns "minors".
The above excerpt from the Web Course "C # development easy to get started"
Notes C # Basics Primer (20) Conditional operators for--c#