Specify StringComparison for correctness
Pass an explicit StringComparison to string operations.
Microsoft docsDescription
String comparison methods that use the current culture by default should be called with an explicit StringComparison.
Cause
A string comparison operation uses a method overload that does not set a System.StringComparison parameter and uses culture-specific string comparison by default. Hence, its behavior will vary based on the current user's locale settings.
Why it matters
Implicit culture-sensitive comparisons cause subtle, hard-to-reproduce bugs across locales.
How to fix violations
To fix a violation of this rule, change string comparison methods to overloads that accept the System.StringComparison enumeration as a parameter. For example, change String.Compare(str1, str2) to String.Compare(str1, str2, StringComparison.Ordinal).
Examples
if (name.StartsWith("admin")) { }if (name.StartsWith("admin", StringComparison.Ordinal)) { }When to suppress
It is safe to suppress a warning from this rule when the library or application is not intended to be localized.