C#


ROSLYN.GLOBALIZATION.CA1310 : Specify StringComparison for correctness (C#)

See Roslyn-Detected C# Warning Classes for more information.

Summary

A string comparison operation uses a method overload that does not set a StringComparison parameter, hence its behavior could vary based on the current user's locale settings. It is strongly recommended to use the overload with StringComparison parameter for correctness and clarity of intent. If the result will be displayed to the user, such as when sorting a list of items for display in a list box, specify 'StringComparison.CurrentCulture' or 'StringComparison.CurrentCultureIgnoreCase' as the 'StringComparison' parameter. If comparing case-insensitive identifiers, such as file paths, environment variables, or registry keys and values, specify 'StringComparison.OrdinalIgnoreCase'. Otherwise, if comparing case-sensitive identifiers, specify 'StringComparison.Ordinal'.

This check corresponds to Roslyn rule CA1310. For full rule details, see the Microsoft website: CA1310.

Properties

Class Name Specify StringComparison for correctness (C#)
Significance reliability
Mnemonic ROSLYN.GLOBALIZATION.CA1310
Categories None
Availability Available for C# only.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Specify StringComparison for correctness (C#)"

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.