Tag Archives: switch statement

Understand ways to end case blocks in C#

There are several ways that you can exit case blocks in a switch statement. For example, consider the following code. string result = “”; int control = 1; switch (control) { case 1: case 2: result = “One or two”; … Continue reading

Posted in syntax | Tagged , , , , , , , , , , | 2 Comments

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

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