A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1310 below:

CA1310: Specify StringComparison for correctness (code analysis) - .NET

Property Value Rule ID CA1310 Title Specify StringComparison for correctness Category Globalization Fix is breaking or non-breaking Non-breaking Enabled by default in .NET 9 No Cause

A string comparison operation uses a method overload that does not set a StringComparison parameter and uses culture-specific string comparison by default. Hence, its behavior will vary based on the current user's locale settings.

Rule description

A string comparison method that uses culture-specific string comparison by default can have potentially unintentional runtime behavior that does not match user intent. It is recommended that you use the overload with the StringComparison parameter for correctness and clarity of intent.

This rule flags string comparison methods that use the culture-specific StringComparison value by default. For more information, see String comparisons that use the current culture.

How to fix violations

To fix a violation of this rule, change string comparison methods to overloads that accept the StringComparison enumeration as a parameter. For example, change String.Compare(str1, str2) to String.Compare(str1, str2, StringComparison.Ordinal).

When to suppress warnings

It is safe to suppress a warning from this rule when the library or application is not intended to be localized.

Suppress a warning

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 CA1310
// The code that's violating the rule is on this line.
#pragma warning restore CA1310

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

[*.{cs,vb}]
dotnet_diagnostic.CA1310.severity = none

For more information, see How to suppress code analysis warnings.

See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4