- [Narrator] Now that we've seen the…if and else if structure, I want to show you…something that does the same thing…but a lot of programmers prefer this structure…to the if and else if structure.…So I'm talking about a switch statement here.…Let's do public string and we'll just flip it around…for this one and say secondary or primary.…As before, we'll take a color…and this time, we're going to do…almost exactly the same thing…but this time, we're going to use a switch statement.…
So what I'll do here is, I'll create a result,…just like I did before.…And I'll make it an empty string…and this time I'll do a switch statement.…So a switch statement works like the if else structure.…You have to put an expression in the…parenthesis for the switch.…In this case, the expression we're looking for is…color.to lower.…And from here, you just build what we call cases.…
So you type in case…and then the case you want to evaluate,…such as red…and then the code that you actually want to execute,…if the case is actually red,…if color.to lower equals red,…
AuthorBruce Van Horn
- Writing unit tests in C#
- Working with simple and multidimensional arrays
- Managing ordered and unordered data with lists
- Evaluating conditions with if-else statements
- Using OR, AND, and NOT operators
- Building loops
- Debugging and handling exceptions
- Creating the final build of your C# project
Skill Level Beginner
C# Object-Oriented Programming Tips and Trickswith Jesse Freeman58m 39s Intermediate
1. Unit Testing and Test-Driven Development
2. Arrays and Collections
3. Flow Control
4. Exception Handling
5. Getting to Production
Next steps1m 57s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.