Open
Description
Analyzer
Diagnostic ID: CA1862: Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
Analyzer source
SDK: Built-in CA analyzers in .NET 8 SDK
Version: SDK 8.0.100
Describe the bug
CA1862 should not be shown when the same variable is on both sides of the comparison.
Steps To Reproduce
if (name.ToLower() == name)
Console.WriteLine("all letters are lowercase");
And the suggested fix changes the behavior completely:
// always true now
if (name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
Console.WriteLine("all letters are lowercase");
Activity