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.

Solution: Switch expression using patterns

Solution: Switch expression using patterns - C# Tutorial

From the course: C# Essential Training 1: Types and Control Flow

Solution: Switch expression using patterns

- [Instructor] For this challenge, your goal was to find a way to create a discount level or calculate a discount level based on an order total, and we're going to try to do that using property pattern matching. Now, one of the changes we'll make to the signature here is we're going to turn this into an expression. So we're going to say customer order switch. That means we're going to switch on that customer order in this expression, so now I'm going to also put a semicolon at the end there to end that statement. And now I want to look at that object coming in, and what do I want to look at? I want to look at the total. I'm going to put a colon, and then I'm going to put my expression, so I can say if it's lower than 100, then outside of the brackets, that leads to low. Put a little comma there. We'll look at the total again. Now I'm going to save if it's greater than 1000. In that case, we want that to result in high.…

Contents