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

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…

Contents