C# switches 🔀

preview_player
Показать описание
C# switch tutorial example explained

#C# #switch #tutorial

using System;

namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// switch = an efficient alternative to many else if statements

Console.WriteLine("What day is it today?");
String day = Console.ReadLine();

switch (day)
{
case "Monday":
Console.WriteLine("It's Monday!");
break;
case "Tuesday":
Console.WriteLine("It's Tuesday!");
break;
case "Wednesday":
Console.WriteLine("It's Wednesday!");
break;
case "Thursday":
Console.WriteLine("It's Thursday!");
break;
case "Friday":
Console.WriteLine("It's Friday!");
break;
case "Saturday":
Console.WriteLine("It's Saturday!");
break;
case "Sunday":
Console.WriteLine("It's Sunday!");
break;
default:
Console.WriteLine(day + " is not a day!");
break;
}

Console.ReadKey();
}
}
}
Рекомендации по теме
Комментарии
Автор

using System;

namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// switch = an efficient alternative to many else if statements

Console.WriteLine("What day is it today?");
String day = Console.ReadLine();

switch (day)
{
case "Monday":
Console.WriteLine("It's Monday!");
break;
case "Tuesday":
Console.WriteLine("It's Tuesday!");
break;
case "Wednesday":
Console.WriteLine("It's Wednesday!");
break;
case "Thursday":
Console.WriteLine("It's Thursday!");
break;
case "Friday":
Console.WriteLine("It's Friday!");
break;
case "Saturday":
Console.WriteLine("It's Saturday!");
break;
case "Sunday":
Console.WriteLine("It's Sunday!");
break;
default:
Console.WriteLine(day + " is not a day!");
break;
}

Console.ReadKey();
}
}
}

BroCodez
Автор

I love how the else if example is literally yandere sim code

michalski
Автор

So concise and to the point! Love your tutorials, thank you so much :)

manggae
Автор

Thanks the video i watched previously never really explained what a switch statement is. This saved me

liamf
Автор

thanks, I was not quite getting it with the microsoft learn class and you help me to get it in less than 3 minutes, u r awesome

juanjoseblancomurillo
Автор

Thank you for these easy to follow and short videos!

bartsworkshop
Автор

bro you make so much sense I'm lucky I found you

GilGaladGaming
Автор

This is a straight to the core and good video!

kingtyphoon
Автор

Thank you very much.That so helpful for me.

AtillaRustemli
Автор

tbh else if and switch looks the same. Switch has a good presentation that's all to it.

hamzarafi
Автор

why the heck am i not subscibe to this man?!?!

christianamplayo
Автор

Couldn’t you make a list, take user input then compare it to the list? If it’s on the list then “It’s (whatever day)” if it’s not on the list just say that’s not a day?

FrankIsDoingThings
Автор

Today I know that birthday is not a day!!!!

vinhnghiang
Автор

Do we use switch case only for strings?

I mean after switch expression I tried to add a condition like a>60 but I got an error message. Besides in the video after the switch statement days of the weeks were written in double quote which is a string definin property.

batusulun
Автор

this type of video only work for me, short and easy to learn, i dont like other video so long and talking nonsence

meowcat
Автор

I’m trying to create a default for a calculator and when I add it still shows the default is there a way to correct this

sickomode