Advanced type usage
In this final section of this chapter, we’ll see how new and old language features help you build better types.
Exploring pattern matching
It turns out that we can use the same style of syntax we used with expressions earlier to conditionally match different objects through pattern matching.
To explain what I mean, let’s start with an example that loops over different boarding passes:
List<BoardingPass> passes = PassGenerator.Generate(); foreach (BoardingPass pass in passes) { if (pass is { Group: 1 or 2 or 3, Flight.Status: FlightStatus.Pending }) { Console.WriteLine($"{pass.Passenger} board now"); } else if (pass is { Flight.Status: FlightStatus.Active ...