Pattern matching with objects
In Chapter 3, Controlling Flow and Converting Types, you were introduced to basic pattern matching. In this section, we will explore pattern matching in more detail.
Creating and referencing a .NET 5 class library
The enhanced pattern matching features are only available in .NET 5 class libraries that support C# 9 or later. First, we will see what pattern matching features were available before the enhancements in C# 9.
- Create a subfolder under
Chapter05
namedPacktLibrary9
. - In Visual Studio Code, navigate to File | Add Folder to Workspace…, select the
PacktLibrary9
folder, and click Add. - Navigate to Terminal | New Terminal and select PacktLibrary9.
- In TERMINAL, enter the following command:
dotnet new classlib
. - In EXPLORER, in the
PeopleApp
folder, click on the file namedPeopleApp.csproj
. - Add a language version element to force the use of the C# 8 compiler, and add a project reference to
PacktLibrary9...