2.5: Switch Statements
File Location
Switch Case
class Program
{
static void Main(string[] args)
{
Console.WriteLine("What's your name?"); //1
string inputName = Console.ReadLine().ToLower(); //2
//3
switch (inputName)
{
case "fred":
Console.WriteLine("Hey Fred, let's go golfing.");
break;
case "karl":
Console.WriteLine("Let's hang.");
break;
case "john":
Console.WriteLine("Sorry, I'm busy right now.");
break;
default:
Console.WriteLine("Hey " + inputName + ", can I call you back in a minute?");
break;
}
}
}Discussion
Practice Challenge
Practice Answer
Last updated