Tag Archives: switch

Compare the performance of switch and if statements in C#

This example compares the performance of switch and if-else statements. Both do roughly the same thing: they check a series of conditions until they find one that is true and then skip the rest. This example compares the speeds of … Continue reading

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

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

Validate a switch statement that uses values from an enumerated type in C#

This example shows how you can validate a switch statement that uses values defined in an enumerated type. Enumerated types and switch statements often go hand-in-hand. You define an enumerated type and then later use a switch statement to see … Continue reading

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