Is it a good practice to compare strings with ==
? Is there an equivalent to s1 == s2
in terms of Compare
and Equals
methods on string
. If one uses those methods, without specifying CultureInfo
FxCop will give a warning, is that a real problem?
The ==
Operator is an ordinal, culture unaware string compare. Its using the same internal call as .Equals
, and is just fine for the "usual" string compare stuff.
If you need Culture-Aware comparings (eg. For GUI purposes ) , like german double-s or ß, use
CultureInfo ci = new CultureInfo("de-DE");
String.Compare("Strasse", "Straße", true, ci)
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