Pattern Matching in C#
Pattern Matching is introduced with C# 7.
It is not a new technic. It's been around for ages. It has been part of programming languages such as F#, Kotlin, and others for a long time.
It makes your code more understandable than you think.
So, what is Pattern Matching in C#?
Pattern Matching is a way to write code that determines what an object is.
By using this technic we can check if an object is X, if its property is set to the value we wish, and so on.
Before Pattern Matching
Pattern Matching
This is another way of the previous code that check what the object is and if it has the value for the property we specified.
Pattern matching can make the code easier to read and understand.
There are many types of pattern matching
In the scope of another post, I will show examples for each of the mentioned patterns.