Skip to content

CA1862 suggestion changing semantics of the comparison. #89740

@buyaa-n

Description

@buyaa-n

CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons suggestion changing semantics of the comparison

Warning: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison

using System;

// These are both lower case Greek Sigmas
string a = "σ";
string b = "ς";

// Prints True
Console.WriteLine(a.Equals(b, StringComparison.InvariantCultureIgnoreCase));

string lowerA = a.ToLowerInvariant();
string lowerB = b.ToLowerInvariant();

// Prints False
Console.WriteLine(lowerA == lowerB);

Originally posted by @MichalStrehovsky in #89630 (comment):
This is changing semantics of the comparison. Do we really have an analyzer that suggests people blindly do this?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions