Locked lesson.
About this lesson
We look at how to use a Switch Statement within our program.
Exercise files
Download this lesson’s related exercise files.
35 - Switch Statement.docx57.6 KB 35 - Switch Statement SOLUTION.docx
59 KB
Quick reference
Switch Statement
Switch allows you to make decisions based on specific cases.
When to use
Use Switch when you have very specific cases to test against.
Instructions
string day = "Monday";
switch(day)
{
case "Monday":
Console.WriteLine("I've got a bad case of the Mondays!");
break;
case "Tuesday":
Console.WriteLine("Tuesday is better than Monday!");
break;
default:
Console.WriteLine("Is it the weekend yet?");
break;
}
Hints & tips
- Switch lets you test against specific cases
Lesson notes are only available for subscribers.