Avvenimenti
Mar 17, 9 PM - Mar 21, 10 AM
Ingħaqad mas-serje meetup biex tibni soluzzjonijiet skalabbli tal-IA bbażati fuq każijiet ta 'użu fid-dinja reali ma' żviluppaturi u esperti sħabi.
Irreġistra issaDan il-brawżer m'għadux appoġġjat.
Aġġorna għal Microsoft Edge biex tieħu vantaġġ mill-aħħar karatteristiċi, aġġornamenti tas-sigurtà, u appoġġ tekniku.
Span<T>
to null
or default
Property | Value |
---|---|
Rule ID | CA2264 |
Title | Do not compare Span<T> to null or default |
Category | Usage |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 9 | As warning |
A Span<T> instance is compared to null
or default
.
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
.
Remove the redundant comparison or make the code more explicit by calling IsEmpty instead.
The following code snippet shows two violations of CA2265 and the fix for the violations.
Span<int> span = new([1, 2, 3]);
// CA2265 violation.
if (span == null) { }
// CA2265 violation.
if (span == default) { }
// Fixes the violation.
if (span.IsEmpty) { }
It's safe to suppress this warning if you meant to compare the span to the empty span.
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable CA2265
// The code that's violating the rule is on this line.
#pragma warning restore CA2265
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA2265.severity = none
For more information, see How to suppress code analysis warnings.
Feedback ta’ .NET
.NET huwa proġett b’sors miftuħ. Agħżel link biex tipprovdi l-feedback:
Avvenimenti
Mar 17, 9 PM - Mar 21, 10 AM
Ingħaqad mas-serje meetup biex tibni soluzzjonijiet skalabbli tal-IA bbażati fuq każijiet ta 'użu fid-dinja reali ma' żviluppaturi u esperti sħabi.
Irreġistra issa