Python for .NET Developers 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 with lots of different options lots of different possibilities you don't necessarily want an if
0:08 else if, else if, else if else if all over the place. Switch is probably what you want. Now you can't put everything under switch but a lot of times
0:16 if it's a direct comparison in quality it can go in here and that's pretty sweet. So what we're going to do is we're going to have
0:21 this program that loops around. It asks you to enter a number between 1 and 4, verifies you entered it and then it's going to switch and then based
0:29 on that it's going to do a Console.WriteLine and break okay. Let's just look at that real quick. Super simple switch statement. I could put 1
0:36 it says 1 is fun. I could put 4. 4 more, 3. 3 and free. If I could put 72 it says no 72 I don't know what's up with that. That is of course
0:46 the default case. Say what number? I don't know what to do with that. Finally, if you hit it, enter it goes away. So here's how we use switch in C#.

Talk Python's Mastodon Michael Kennedy's Mastodon