The "best" (the term is used ironically) method is "=="; it makes semantic comparison. It is not redundant and is more readable. And
System.Object.ReferenceEquals
gives you referential comparison. By the way, you can define your own equality (this is often needed) for your type, and in this way using referential equality is the must, because otherwise you would have stack overflow (if you define
Equals
or "==" and use it in the definition, usually for comparison with null; do you need to explain why?). The semantic of
">" or "<"
can be got using
System.String.CompareTo
.
Please see:
http://msdn.microsoft.com/en-us/library/system.string.aspx[
^].
Choose those methods which fit your purpose.
[EDIT]
I almost forgot: semantic string comparison may be case-sensitive or not and depend on culture. I mean, in one culture two technically different strings may be considered equal, or one less then another, but the result could be different in another culture. See all the
System.String.Compare
method, see the reference above.
—SA