condition ? expression1 : expression2
If the condition is true, expression 1 is evaluated. Alternatively, if the condition is false, expression 2 is evaluated.
Example:
Random random = new Random( DateTime.Now.Millisecond );
string response = random.Next( 1, 9 ) < 5 ? "the number is less than 5" : "the number is greater than or equal to 5";
No comments:
Post a Comment