From the course: Advanced C# Programming Concepts
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Overview of pattern matching - C# Tutorial
From the course: Advanced C# Programming Concepts
Overview of pattern matching
- [Presenter] In this chapter, we're going to take a look at the pattern matching feature of C# which was first introduced to the language back in C#7 and has had several enhancements since then. So first, let's understand what pattern matching is. To be clear, I am not referring to regular expression patterns here. Those are separate from C# itself. Pattern matching is the process of examining an expression to see if it has certain characteristics and then taking specific actions based on the result. These checks are performed using the is operator and an enhanced version of the switch statement. The thing about pattern matching is it doesn't technically add new functionality to the C# language in the sense that you can already accomplish the same results by using C# constructs. However, it makes certain kinds of logical operations easier to write and more concise than a large block of if-else statements or complex switch statements. There are a number of different types of patterns…