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 switch Statement

The switch statement enables a program to select from multiple actions, based on the value of a controlling expression also called a switch expression. The logic implemented by the switch statement is, therefore, somewhat similar to that of a multibranch if-else statement. To demonstrate the similarities and differences between a switch statement and a multibranch if-else statement, let's have a look at an example.

The program of Listing 8.10 implements the logic behind a “talking” dishwasher by using a multibranch if-else statement. By choosing one of the numbers 1, 2, or 3, the user can select one of the three programs featured by the dishwasher—1: Economy, 2: Intensive, 3: Universal. Every time a choice has been made, ...

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