Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What do you call this type of conditional statement?

var testVariable = firstVariable == null ? 0 : 10;

This is an example of a small simple code. I understand vaguely that it is performing somewhat of a similar concept of a conditional statement (just like an if statement). But what do you call this name of coding if it is utilizing the " ? : " symbol?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The ? character is the first part of the ternary conditional operator.

"Ternary" because the expression has three parts, unlike most operators, which are two-part "binary" operators (think addition or assignment) or one-part "unary" operators (think increment ++ or negation !). "Conditional" because the expression evaluates a condition to produce a result.

Reading the linked documentation, we see this exceprt:

Beginning with C# 9.0, conditional expressions are target-typed.

Therefore, the documentation refers to this as a "conditional expression".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading