C# switches 🔀
Ғылым және технология
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();
}
}
}
Пікірлер: 57
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(); } } }
@NinetyEight418
4 ай бұрын
can i use "if" or "while" in there?
So concise and to the point! Love your tutorials, thank you so much :)
I love how the else if example is literally yandere sim code
@leg1187
Жыл бұрын
else if statements are only good if you only have a couple options to choose in your application. Otherwise, if you're like me and you're into OS Development you're going to need a TON of if statements. SO that's where case and switch come in! ;)
@Crecross
Жыл бұрын
@@leg1187 You're literally saying what he has already said in the video 💀
@leg1187
Жыл бұрын
@@Crecross Yea is that a issue?
@KathushGaming
Жыл бұрын
You are absolutely right Bro
Thank you for these easy to follow and short videos!
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
VERY useful! Thank you!
bro you make so much sense I'm lucky I found you
Enjoying your lesson
This is a straight to the core and good video!
Thank you very much.That so helpful for me.
Thanks bro! U the best!
Thanks for the video Bro
Thanks!
Thank you 😊
lovely😀
Thanks bro.
Thanks again
very easily explained
Common bro w
Random comment, thanks for excisting
thanks :)
Very simple
thanks Bro
thanks
easy simple quick
why the heck am i not subscibe to this man?!?!
👍
i love you
lesson check😇
noice
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
0:57 is what you came here for
come to Brazil.
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?
Today I know that birthday is not a day!!!!
tbh else if and switch looks the same. Switch has a good presentation that's all to it.
@asadaduf
Жыл бұрын
Oh it else if is the same as switch alright. But it's not the super one.
@nelliesnest5919
10 ай бұрын
The main diff is you don't need { } around every individual case, it makes the code a lot cleaner and much harder to bust up lol
Here we go :v
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.
@luckyizzac
6 ай бұрын
I dont think you can put any thing other than switch related stuff inside switch blocks (you can put it inside case and default blocks), because inside the switch blocks, the code is not read line by line like an if-else branch, the algorithm inside the switch block is different
@tubetimeline
5 ай бұрын
Hi batusulun, Switch can also be used with integer values. It is often used with ages for things like sorting for grade school, middle school and college.
great!!!!! this type of video only work for me, short and easy to learn, i dont like other video so long and talking nonsence
I don't understand what is default at the end.
@magasiku4710
Жыл бұрын
It is the default thing the program writes, if the given data is none of the cases above
@ZeeWolfed
Жыл бұрын
@@magasiku4710 ah okay thanks mate
@Username92381
8 ай бұрын
It's alternative choice Bruv, you can't hower all of cases
Random Comment
random comment 😃
لماذا الترجمة للعربية مزيفة 😡 !
Console.WriteLine("please enter the names of your family members"); string names =Console.ReadLine(); switch (names) { case "Tristan": Console.Beep(); Console.WriteLine("Right,He is your son "); break; case "Artashes": Console.Beep(); Console.WriteLine("Right,he is your oldest son"); break; case "Albertina": Console.Beep(); Console.WriteLine("Right,she is your wife"); break; case "Tigran": Console.Beep(); Console.WriteLine("Right,its YOu"); break; Console.Beep(); default: Console.Beep(); Console.WriteLine("That person is not a family member"); break;
@T1T3T4
9 ай бұрын
Actually the beep before the default shouldn't be there, it isn't connected to anything so either it will give an error or it will just never run