O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Conditional Operator

As shown in Syntax Box 8.12 the conditional operator combines three expressions with the two symbols—question mark ? and colon :. It will return either the value of ExpressionA or the value of ExpressionB, depending on whether the Boolean expression to the left of the question mark is true or false. If true, the value of ExpressionA is returned; otherwise, the value of ExpressionB is returned.

Syntax Box 8.12 The Conditional Operator

						<Boolean_expression> ? <ExpressionA> : <ExpressionB>
					

Note

The conditional operator is the only operator in C# to combine three expressions, so it is also referred to as the ternary operator. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required