From the course: C# Essential Training 1: Types and Control Flow
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Switch statement vs. switch expression - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
Switch statement vs. switch expression
- [Instructor] Starting on line 28, we've used a switch statement, which has the switch key word. And then the item we're evaluating in this case padChar, and then the curly braces wherein we define our case statements, the different branches. And in each case, we can have any number of different steps here that we can execute. In contrast, we also have the switch expression that was introduced in C-sharp eight. I'm going to add a new method here, and I'm going to say that it's going to return a shift days. Let's say, get shift days. And that's going to take in a day of the week. We'll call that day. And I'm going to use an expression body method definition. So you can see we have that coming across here. And now, we'll just say day switch. And now, I can have an expression inside of here. So it's slightly different in that we're declaring first, the item we're evaluating the day, and then the switch statement. And now, we're going to have a series of expressions. For example, a day…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
If and switch revisited5m 26s
-
(Locked)
Switch statement vs. switch expression4m 55s
-
(Locked)
Using the is expression5m 22s
-
(Locked)
Introduction to patterns3m 46s
-
(Locked)
Constant, relational, and logical patterns3m 17s
-
(Locked)
Property pattern4m 22s
-
(Locked)
Guard conditions3m 57s
-
(Locked)
Solution: Switch expression using patterns2m 16s
-
(Locked)
-