Skip to content

Files

Latest commit

 

History

History
28 lines (19 loc) · 595 Bytes

File metadata and controls

28 lines (19 loc) · 595 Bytes

Pattern: Comparing span to null/default

Issue: -

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.

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) { }

Further Reading