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

  • @BroCodez
    @BroCodez3 жыл бұрын

    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

    @NinetyEight418

    4 ай бұрын

    can i use "if" or "while" in there?

  • @manggae613
    @manggae6132 жыл бұрын

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

  • @michalski9141
    @michalski91412 жыл бұрын

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

  • @leg1187

    @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

    @Crecross

    Жыл бұрын

    @@leg1187 You're literally saying what he has already said in the video 💀

  • @leg1187

    @leg1187

    Жыл бұрын

    @@Crecross Yea is that a issue?

  • @KathushGaming

    @KathushGaming

    Жыл бұрын

    You are absolutely right Bro

  • @bartsworkshop
    @bartsworkshop4 ай бұрын

    Thank you for these easy to follow and short videos!

  • @juanjoseblancomurillo8826
    @juanjoseblancomurillo88266 ай бұрын

    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

  • @darkbrotherhood5363
    @darkbrotherhood5363 Жыл бұрын

    VERY useful! Thank you!

  • @GilGaladGaming
    @GilGaladGaming2 жыл бұрын

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

  • @owethumoyo4020
    @owethumoyo4020 Жыл бұрын

    Enjoying your lesson

  • @kingtyphoon
    @kingtyphoon7 ай бұрын

    This is a straight to the core and good video!

  • @AtillaRustemli
    @AtillaRustemli Жыл бұрын

    Thank you very much.That so helpful for me.

  • @marsivanova2008
    @marsivanova2008 Жыл бұрын

    Thanks bro! U the best!

  • @spartanranger
    @spartanranger2 жыл бұрын

    Thanks for the video Bro

  • 3 жыл бұрын

    Thanks!

  • @jackchitte
    @jackchitte4 ай бұрын

    Thank you 😊

  • @Maaikus
    @Maaikus Жыл бұрын

    lovely😀

  • @pawloaspaja289
    @pawloaspaja2892 жыл бұрын

    Thanks bro.

  • @alexiscoe1040
    @alexiscoe10403 жыл бұрын

    Thanks again

  • @atal8027
    @atal8027 Жыл бұрын

    very easily explained

  • @nkosisiya_
    @nkosisiya_3 ай бұрын

    Common bro w

  • @TheMasterswordish
    @TheMasterswordish Жыл бұрын

    Random comment, thanks for excisting

  • @bozhenakondrat4169
    @bozhenakondrat41692 жыл бұрын

    thanks :)

  • @PixelPickleWaffle
    @PixelPickleWaffleАй бұрын

    Very simple

  • @juriappo354
    @juriappo3542 жыл бұрын

    thanks Bro

  • @nikolaivanov8007
    @nikolaivanov8007 Жыл бұрын

    thanks

  • @user-sm6wu1px7s
    @user-sm6wu1px7s Жыл бұрын

    easy simple quick

  • @christianamplayo3798
    @christianamplayo37989 ай бұрын

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

  • @eastern815
    @eastern8157 ай бұрын

    👍

  • @joji5577
    @joji55777 ай бұрын

    i love you

  • @whitedinamo
    @whitedinamo2 жыл бұрын

    lesson check😇

  • @budderrar5751
    @budderrar5751 Жыл бұрын

    noice

  • @sickomode9966
    @sickomode99667 ай бұрын

    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

  • @bobojenkins5805
    @bobojenkins58056 ай бұрын

    0:57 is what you came here for

  • @The_Ancient_Guardian
    @The_Ancient_Guardian Жыл бұрын

    come to Brazil.

  • @FrankIsDoingThings
    @FrankIsDoingThings23 күн бұрын

    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?

  • @vinhnghiang1273
    @vinhnghiang1273Күн бұрын

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

  • @hamzarafi5387
    @hamzarafi5387 Жыл бұрын

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

  • @asadaduf

    @asadaduf

    Жыл бұрын

    Oh it else if is the same as switch alright. But it's not the super one.

  • @nelliesnest5919

    @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

  • @McPatoo
    @McPatoo8 ай бұрын

    Here we go :v

  • @batusulun7297
    @batusulun72977 ай бұрын

    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

    @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

    @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.

  • @meowcat2363
    @meowcat2363 Жыл бұрын

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

  • @ZeeWolfed
    @ZeeWolfed Жыл бұрын

    I don't understand what is default at the end.

  • @magasiku4710

    @magasiku4710

    Жыл бұрын

    It is the default thing the program writes, if the given data is none of the cases above

  • @ZeeWolfed

    @ZeeWolfed

    Жыл бұрын

    @@magasiku4710 ah okay thanks mate

  • @Username92381

    @Username92381

    8 ай бұрын

    It's alternative choice Bruv, you can't hower all of cases

  • @FukSN
    @FukSN Жыл бұрын

    Random Comment

  • @drea7363
    @drea7363 Жыл бұрын

    random comment 😃

  • @syeid_mot
    @syeid_mot4 ай бұрын

    لماذا الترجمة للعربية مزيفة 😡 !

  • @tigranziberov-mkrtchyan6375
    @tigranziberov-mkrtchyan63759 ай бұрын

    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

    @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

Келесі