Introducing C#11: Pattern match Span
and ReadonlySpan on a constant string
Before C# 11 it was impossible to use pattern matching on a constant string for Span<char> and ReadOnlySpan<char>. If you are not familiar with Pattern Matching you can read the following post: https://anthonygiretti.com/2020/06/23/introducing-c-9-improved-pattern-matching/. The reason why Microsoft updates C# to support pattern matching here is because using Span<char> and ReadOnlySpan<char> are the most performant way to compare string most of time in place of a string.
Pattern matching in real life
Here are the most likely ways you might use Span<char> or ReadOnlySpan<char> pattern matching on a constant string:
That’s it 🙂