Pattern: Comparing span to null
/default
Issue: -
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
.
Example of incorrect code:
Span<int> span = new([1, 2, 3]);
// CA2265 violation.
if (span == null) { }
// CA2265 violation.
if (span == default) { }
Example of correct code:
// Fixes the violation.
if (span.IsEmpty) { }