If you have a look at the corresponding reference sources
https://referencesource.microsoft.com/#mscorlib/system/string.cs,bda3b2c94b5251ce
public static int Compare(String strA, String strB, bool ignoreCase)
{
if (ignoreCase) {
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase);
}
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.None);
}
https://referencesource.microsoft.com/#mscorlib/system/string.cs,0be9474bc8e160b6
public static int Compare(String strA, String strB, StringComparison comparisonType)
{
...
// Agrument validation, reference equality, null test
switch (comparisonType) {
...
case StringComparison.CurrentCultureIgnoreCase:
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreCase);
https://referencesource.microsoft.com/#mscorlib/system/string.cs,d47c1f57ad1e1e6e
public static bool Equals(String a, String b, StringComparison comparisonType) {
...
// Agrument validation, reference equality, null test
switch (comparisonType) {
...
case StringComparison.CurrentCultureIgnoreCase:
return (CultureInfo.CurrentCulture.CompareInfo.Compare(a, b, CompareOptions.None) == 0);
you'll find these three methods being equal one another. As for other ways, Regex.IsMatch
is definitely an overshoot (all you have to do is to compare strings); ToLower()
can be tricky when dealing with culture specific letters, see
https://en.wikipedia.org/wiki/Dotted_and_dotless_I
that's why a better design is to declare your intends clearly (= I want to compare strings) then mask them (and let the system decieve you)