ReSharper 2024.1 Help

Code inspection: Replace 'SequenceEqual' with constant pattern

If you deal with parsing of character spans, you probably use MemoryExtensions.SequenceEqual method a lot. C# 11 introduces a shorthand for this kind of checks, enabling you to simply pattern-match spans of characters against string literals with is or switch expressions.

This inspection reports usages of SequenceEqual() in such contexts and helps you upgrade to a more concise syntax.

public static bool IsHeader(ReadOnlySpan<char> header) { return header.SequenceEqual("<=HEADER=>"); }
public static bool IsHeader(ReadOnlySpan<char> header) { return header is "<=HEADER=>"; }
Last modified: 08 May 2024