SHARE:

Introducing C#11: Pattern match Span and ReadonlySpan on a constant string

Introduction

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 🙂

Written by

anthonygiretti

Anthony is a specialist in Web technologies (14 years of experience), in particular Microsoft .NET and learns the Cloud Azure platform. He has received twice the Microsoft MVP award and he is also certified Microsoft MCSD and Azure Fundamentals.
%d bloggers like this: