by Michael S. Kaplan, published on 2006/08/16 03:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/08/16/702104.aspx
Back when I wrote Invariant vs. Ordinal, the third, two of the interesting points I made were that, in most cases:
Now obviously this is a much simpler set of rules (that actually cover the majority of the default cases) in a much easier to grok way than all fifteen pages of the rules captured in The New String Recommendations.
There is something else that is interesting about these two rules, which you can see by looking at the way .NET's System.String works:
In other words, if for most purposes you forget about the entirety of the New Recommendations for Using Strings in Microsoft .NET 2.0 and simply use the default Equals and Compare methods off of System.String, then most of the worries surrounding string comparisons that are really caused by the fact that strings are overloaded to handle both values that would be used in identifiers and values that would be used in sorting go away completely.
Now obviously there are exceptions to the rule here, and those exceptions can behandled with the plethora of methods that are available. But as rules go, this makes for a much simpler default.
And it is already built in to the BCL, and has been since the very beginning!
All you have to do is stay the hell away from the most common misuse of string.Compare(string, string) == 0, since that is really supposed to be using string.Equals....
This post brought to you by ឡ (U+17a1, a.k.a. KHMER LETTER LA)
go to newer or older post, or back to index or month or day