Bald Bearded Builder
csharp/how-pattern-matching-saves-your-day

How Pattern Matching Saves Your Day!

ASP.NET Core exception handling progresses from built-in middleware and custom middleware to modular .NET 8 `IExceptionHandler` implementations registered in priority order.

Loads from YouTube when you press play

Transcript 1 topic

Pattern matching with boxed values

0:00

Oh, dang it. You boxed a value type into an object and now your equality and inequality operators won't compile. That's because they need compatible types. But pattern matching don't care. Check out this code.

We couldn't run that line five because those aren't compatible types. But our pattern matching will run and give us our output just like we expect. That's because the pattern matching checks the runtime value inside the object versus the constant. Clean, readable, and no unboxing ceremony required.

Sign in to join in. Reading needs nothing.