Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CA1307: Specify StringComparison

TypeName

SpecifyStringComparison

CheckId

CA1307

Category

Microsoft.Globalization

Breaking Change

Non-breaking

A string comparison operation uses a method overload that does not set a StringComparison parameter.

Many string operations, most important the Compare and Equals methods, provide an overload that accepts a StringComparison enumeration value as a parameter.

Whenever an overload exists that takes a StringComparison parameter, it should be used instead of an overload that does not take this parameter. By explicitly setting this parameter, your code is often made clearer and easier to maintain.

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).

It is safe to suppress a warning from this rule when the library or application is intended for a limited local audience and will therefore not be localized.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.