Tag Archives: ternary operator

Compare the performance of if-else and switch statements in C#

The example Compare the speeds of the conditional operator (ternary operator ?:) and the if-else statement in C# compares the performance of two kinds of conditional tests. Johnny Boy pointed out that this didn’t include another kind of conditional statement: … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , , , , , | Leave a comment

Compare the speeds of the conditional operator (ternary operator ?:) and the if-else statement in C#

The conditional operator (also called the ternary operator) looks confusing enough that some programmers assume it must be more efficient than a comparable but longer if-else statement. This example uses the following code to compare the speeds of the conditional … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , | 5 Comments

Use the conditional operator (ternary operator ?:) in C#

The conditional operator (also called the ternary operator) evaluates a boolean expression and returns one of two values depending on the result. If the expression is true, the operator returns the first value. If the expression is false, the operator … Continue reading

Posted in syntax | Tagged , , , , , , , , , | Leave a comment