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 - 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.…
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)
-