Code Inspection: Specify string comparison explicitly
Similarly to the Specify a culture in string conversion explicitly, this inspection helps to avoid problems with running your code on machines with different culture settings.
When stings are compared with the equality operators (==
and !=
) or the Equals()
method, comparison results may differ depending on the machine's locale. The canonical example is the Turkish where there is a lowercase dotless "ı" with the corresponding uppercase "I", and a lowercase "i" with an uppercase "İ" with the dot.
To make clear how exactly the strings will be compared, ReSharper suggests to use the String.Equals()
method overloads to handle casing and culture-aware comparison. For example, a case-insensitive comparison, such as
could be replaced with
where it is immediately clear that the strings are compared taking the culture settings into consideration.
If the comparison is explicitly made culture-insensitive, then it is also suggested to use String.Equals()
with the InvariantCultureIgnoreCase
in the comparison rule parameter, for example:
could be replaced with