C# FOUNDATIONSChapter 1 · C# Foundations
Choice with switch
A switch statement evaluates an expression and matches it against one of several case blocks. It is cleaner than a long chain of else-if statements when checking a single value.
Worked example
string mood = "dreamy";
switch (mood) {
case "neon":
Console.WriteLine("Bright night");
break;
case "dreamy":
Console.WriteLine("Soft stars");
break;
default:
Console.WriteLine("Neutral sky");
break;
}How it reads
- switch (mood) evaluates the variable mood
- case "neon": defines a block that runs if mood equals "neon"
- break; exits the switch statement, avoiding fallthrough

Cloud tip: C# requires a control flow jump (like break, return, or throw) at the end of each non-empty case block. Case fallthrough is not allowed.


