I have the following line of code:
String.Equals("strasse", "straße", StringComparison.InvariantCultureIgnoreCase)
In .net 4.7.2, this returns true.
In .net 5 (and .net 6), this returns false.
Why?
I'm currently learning how comparing strings works in C#. NET. and have come across an unexpected result that I do not fully understand.
When using the overloaded method String.Equals(string,string,Stringcomparison)
to compare string :"strasse"
and string : "straße"
with the following Stringcomparison :
Console.WriteLine(String.Equals("strasse", "straße", StringComparison.OrdinalIgnoreCase));
Console.WriteLine(String.Equals("strasse", "straße", StringComparison.CurrentCultureIgnoreCase));
Console.WriteLine(String.Equals("strasse", "straße", StringComparison.InvariantCultureIgnoreCase));
I get the following result :
False
False
False
I expected the first one to return false but both the second and third line to return true. I first though maybe my CurrentCulture was the issue, so to be sure is et both the CurrentCulture and CurrentUICulture to :
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("de-DE");
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("de-DE");
Did I incorrectly understand String comparison ? or am I missing something obvious here ?
Thanks in advance for anyone willing to help me understand