Python for the .NET developer Transcripts
Chapter: The Python Language
Lecture: C# switch statements

Login or purchase this course to watch this video and the rest of the course contents.
0:00 When you have a conditional situation
0:02 with lots of different options
0:04 lots of different possibilities
0:05 you don't necessarily want an if
0:07 else if, else if, else if
0:10 else if all over the place.
0:11 Switch is probably what you want.
0:12 Now you can't put everything
0:14 under switch but a lot of times
0:15 if it's a direct comparison in quality
0:17 it can go in here and that's pretty sweet.
0:19 So what we're going to do is we're going to have
0:20 this program that loops around.
0:22 It asks you to enter a number
0:23 between 1 and 4, verifies you entered it
0:26 and then it's going to switch and then based
0:28 on that it's going to do a Console.WriteLine
0:29 and break okay.
0:31 Let's just look at that real quick.
0:32 Super simple switch statement.
0:34 I could put 1
0:35 it says 1 is fun.
0:37 I could put 4.
0:38 4 more, 3.
0:39 3 and free.
0:40 If I could put 72 it says no 72 I don't know
0:43 what's up with that.
0:44 That is of course
0:45 the default case.
0:47 Say what number?
0:49 I don't know what to do with that.
0:50 Finally, if you hit it, enter
0:51 it goes away.
0:52 So here's how we use switch
0:54 in C#.