Pattern matching with objects
In Chapter 3, Controlling Flow, Converting Types, and Handling Exceptions, you were introduced to basic pattern matching. In this section, we will explore pattern matching in more detail.
Creating and referencing a .NET 6 class library
The enhanced pattern matching features are only available in modern .NET class libraries that support C# 9 or later.
- Use your preferred coding tool to add a new class library named
PacktLibraryModern
to the workspace/solution namedChapter05
. - In the
PeopleApp
project, add a reference to thePacktLibraryModern
class library, as shown highlighted in the following markup:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup> <ItemGroup> ...