All rules
CA2265Usage Enabled by default: As warning

Do not compare Span<T> to null or default

Do not compare Span<T> to null or default

Microsoft docs

Description

Comparing a span to null or default might not do what you intended. default and the null literal are implicitly converted to Span<T>.Empty.

Cause

A System.Span1 instance is compared to null or default`.

How to fix violations

Remove the redundant comparison or make the code more explicit by calling System.Span`1.IsEmpty instead.

Example

#pragma warning disable CA2265
// The code that's violating the rule is on this line.
#pragma warning restore CA2265

When to suppress

It's safe to suppress this warning if you meant to compare the span to the empty span.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0