From the course: Advanced C#: Language Features
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Position patterns - C# Tutorial
From the course: Advanced C#: Language Features
Position patterns
- [Instructor] Now we're going to look at the positional pattern which was introduced in C# 8. The positional pattern lets us take advantage of something that we learned about earlier in the course when we looked at using the deconstruction feature to return tuples of values. Let's go ahead and open up the PositionalPattern folder and open the code. So this pattern enables us to deconstruct an expression result and then match the resulting values against the corresponding nested patterns. So let's try this out. Let's imagine that we have a program that calculates the amount of a group discount available when purchasing tickets to an event. I have a function here named GetGroupTicketPriceDiscount. This is going to return the discount percentage based upon some criteria which are the size of the group and the date that the visit is happening. So the first technique I want to show is that you can switch on a tuple of…