Skip to content

Latest commit

 

History

History
17 lines (11 loc) · 1.04 KB

MA0001.md

File metadata and controls

17 lines (11 loc) · 1.04 KB

MA0001 - StringComparison is missing

String manipulation methods in .NET do not all use the same default rules for string comparison by culture and case. For instance, string.Equals(string, string) uses StringComparison.Ordinal whereas IndexOf(String) uses StringComparison.CurrentCulture. So, you should use an overload that does not rely on default behavior.

MA0001 only reports a diagnostic when the default comparison for the method is Ordinal or OrdinalIgnoreCase. MA0074 reports all others cases.

string.Equals("a", "b"); // non-compliant as the default comparison of string.Equals is Ordinal

// Should be
string.Equals("a", "b", StringComparison.Ordinal);

Additional resources