 Hey everybody, this is Brian and welcome to the fifth C sharp tutorial today. We are going to talk about the switch statement Now if you know visual basic the switch statement will be very familiar to We're just gonna make a very simple boolean here. We're gonna say right out of boolean juice. Sorry variable. We're gonna say int age Equals and we're just gonna say 10 Now what we're gonna do here is say switch and you have to give it the variable age and Then you give it a function block or a code block now you have to give it a certain amount of cases you say case and say zero Break Now You're probably looking at this going what in the world is this well, I'm gonna explain it very quickly After I add a few of these Now what we're doing here. This is similar to an if statement is we're saying okay evaluate this expression now switch and Each one of these cases is a different switch We're saying if the age is zero and then let's say if the age is let's say five and let's just say 10 Do something at each one of these levels. So if it's zero say console We'll say right line You have not been born yet You know, somebody's obviously trying to fool us in saying they're not old at all. So we'll show them console right line too young for school and console 10 Or console 10 cheese case 10. We're gonna say okay, you should be in school by now Now default is a special one default says you've gone through the entire Switch cases all of them and nothing has fit So say I don't know Now what's gonna happen here is we're gonna run this program. It's gonna go into the main function here It's going to say we have an integer of age equals 10 and you notice how when you highlight age I highlight see here also because it's showing you where it's used Now we're saying switch age. So every time we have a case It's going to say is age equals zero. Well, no, is it equal five? No is equal 10. Yes, it's going to print this Now break that stops what's called fall through in some languages. You can get rid of break and you can say For example zero five no break in between so it'll actually say is it zero No, keep going is it five and it'll evaluate. This is one big expression We don't want that and actually you cannot do that in C sharp So you have to have a break every single time If you're wondering why it looks like that. Well, it's because C sharp is very closely tied to C plus plus and It tries to mimic the syntax to make it easier on people So let's do that and then let's just add our console dot read line Or we just do a console dot read Press f5 to run and sure enough you should be in school because we said 10 now. Let's give it a different age here Let's actually say 43 43 wasn't in our our cases. So it's gonna say I don't know because it broke down into the default Down here. So that in a nutshell is the switch statement very simple very powerful Why would you use the switch statement? Well, if you didn't you would have to say if You know this else if This you know, you just keep going and going and going and it gets Maddening and you don't want to do that. So when you have something where you want to say, okay Do something at different levels if you're zero if you're five if you're ten use a switch statement This is Brian. Thank you for watching. I hope you found this tutorial educational and entertaining