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.
String.Equals
over String.Compare
Property | Value |
---|---|
Rule ID | CA2251 |
Title | Use String.Equals over String.Compare |
Category | Usage |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 9 | No |
The result of a call to String.Compare is compared to zero.
String.Compare is designed to produce a total-order comparison that can be used for sorting. If you only care whether the strings are equal, it is both clearer and likely faster to use an equivalent overload of String.Equals.
To fix violations of this rule, replace the expression comparing the result of String.Compare with a call to String.Equals.
It is safe to suppress warnings from this rule.
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 CA2251
// The code that's violating the rule is on this line.
#pragma warning restore CA2251
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA2251.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