Skip to main content
Source: AL0004ToAL0005SpanComparisonAnalyzer.cs

Description

When comparing Span and a constant, use pattern matching instead of equality operators, unless you want to compare addresses.

Bad Code

if (span == "hello")

Good Code

if (span is "hello")

Properties

  • Category: Usage
  • Severity: Warning
  • Enabled by default: True
  • Code fix available: True

Configuration

dotnet_diagnostic.AL0004.severity = warning