What are the reasons not to use "==" to compare localized strings in .NET? How would the comparison execute in regards to the CultureInfo if I do use it?
If you compare culture-aware strings with ==, for example "Strasse" with "Straße", it returns false.
If you need culture-aware comparings for UI stuff (Sorting of Listview), you use String.Compare with the related CultureInfo.
CultureInfo ci = new CultureInfo("de-DE");
String.Compare("Strasse", "Straße", true, ci) // Returns zero
==
is culture-insensitive - it's a simple ordinal comparison. So two strings which are culturally equal - or even equal in terms of other canonicalization forms - may not be equal via ==
. It basically treats each string like a char
array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With