Pattern Matching with Objects
Learn about pattern matching by defining various flight passenger types and using switch expressions in C# 9 or later to calculate their flight costs.
We'll cover the following...
We'll cover the following...
Now, we will explore pattern matching. Through pattern matching, we will witness how C# elegantly handles different scenarios, making it a versatile tool for developers.
Defining flight passengers
In this example, we will define some classes that represent various types of passengers on a flight, and then we will use a switch
expression with pattern matching to determine the cost of their flight:
Step 1: In the PacktLibraryNetStandard2
project or ...