Comparing Boolean values with the conditional logic operator

The conditional logic operator evaluates a Boolean expression. The result of the expression has one value if the input expression evaluates to True and another if the input expression evaluates to False. Expressions that use conditional operators are tertiary expressions because three operands are required to perform a conditional logic operation. The conditional operator is the only tertiary expression supported in the C# language.

Writing a conditional operator involves writing the input expression, followed by a question mark. The True value comes next, followed by a colon, followed by the False value:

You can read this statement as "Compare the value of MyVariable with 123. If that expression evaluates to True, set the value of MyInteger to 3. If that expression evaluates to False, set the value of MyInteger to 5."

0 0

Post a comment