Skip to content
Bradley Grainger edited this page Dec 29, 2018 · 1 revision

Use operator== or a non-ordinal StringComparison

string.Equals(string, string) always performs an ordinal (case-sensitive, culture-insensitive) comparison. The shorter form x == y should be preferred instead.

Alternatively, if a non-ordinal comparison is needed, use string.Equals(string, string, StringComparison) and explicitly specify a StringComparison that is not StringComparison.Ordinal.

Suggested Fixes

  • Use the equality operator.
  • Explicitly specify a StringComparison that is not StringComparison.Ordinal.

Limitations

The suggested fix always uses OrdinalIgnoreCase comparison; in some cases, culture-sensitive comparison would be better.

Clone this wiki locally