C#

C#

Made by DeepSource

Use StringComparison.OrdinalIgnoreCase for case insensitive comparisons CS-R1017

Anti-pattern
Major

While converting strings to lower/upper case and then comparing might work to perform a case insensitive comparison, the safer, reliable, and performant alternative is to invoke the string.Equals method while specifying the StringComparison.OrdinalIgnoreCase enum.

Examples

Bad Practice

var areEqual = str1.ToLower() == str2.Lower();

Recommended

var areEqual = string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase);

Reference