What is the difference (in bref) between (.NET)
myString == otherString
and
myString.CompareTo(otherString) == 0
There's no difference, except when myString is null, in which case myString.CompareTo(otherString) throws an error (NullReferenceException). Also, using CompareTo is a little bit slower than ==.
Only use CompareTo when you are interested in knowing if a string is before or after another one in an alphabetical sorting of them. For example "Car".CompareTo("Cat") returns -1 because "Car" is before "Cat" when ordered alphabetically.
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