Chapter 19 The Case Decision Structure

19.1 The Case Decision Structure

The case decision structure is a simplified version of the multiple-alternative decision structure. It helps you write code faster and increases readability, especially for algorithms that require complex combinations of decision structures. The case decision structure is used to expand the number of alternatives in the same way as the multiple-alternative decision structure does.

The general form of the C# statement is

switch (a variable or an expression to evaluate) {
case value-1:
A statement or block of statements 1
break;
case value-2:
A statement or block of statements 2
break;
case value-3:
A statement or block of statements 3
break;
.
.
.
case value-N:
A statement ...

Get C# and Algorithmic Thinking for the Complete Beginner now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.