Re: String.Compare seems to fail when it should not

Sébastien Lorion <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
I especially like the comments at the bottom ... That's funny and sad at the
same time :p

Don't you DARE close this without fixing like you did with
TypeConverter.IsValid.
 Posted by IDisposable1 on 11/16/2006 at 2:44 PM

They dared
 Posted by Marc Gravell on 11/27/2006 at 10:10 PM

On Mon, Sep 8, 2008 at 10:03 PM, Mark Hurd <[email protected]> wrote:

> On Tue, Sep 9, 2008 at 5:57 AM, Sébastien Lorion
> <[email protected]> wrote:
> > My bottom line is, if I control the data and I am 100% sure it won't
> contain
> > problematic chars, then by all means, I will use ordinal compare and get
> the
> > speed increase. Otherwise, as a non English native myself, I want to make
> my
> > apps international and so, I will use the culture aware comparison (and
> > other operations).
>
> Just be careful what you use the comparison for... Note this highly
> rated Connect "Won't Fix":
>
>
> https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=236900
>
> I bet this'd be a bugger of a bug to locate.
>
> In this snippet you'd expect the two SortedLists to be identical, but
> they're not, and the reason's clear -- the strings are s1<s2<s3<s1!
>
> Dim s1 As String = "-0.67:-0.33:0.33"
> Dim s2 As String = "0.67:-0.33:0.33"
> Dim s3 As String = "-0.67:0.33:-0.33"
> Console.WriteLine(s1.CompareTo(s2))
> Console.WriteLine(s2.CompareTo(s3))
> Console.WriteLine(s3.CompareTo(s1))
> Dim l, m As New SortedList(Of String, Integer)
> l.Add(S1,1)
> l.Add(S2,2)
> l.Add(S3,3)
> m.Add(S3,3)
> m.Add(S2,2)
> m.Add(S1,1)
> For Each i in m
>  Console.WriteLine(i)
> Next
> For Each j in l
>  Console.WriteLine(j)
> Next
>
> Now I know why FXCop and the built-in VS2008 Code Analysis always says
> to specify the comparer and cultureinfo -- it's not just for performance!
>
> Regards,
> Mark Hurd, B.Sc.(Ma.) (Hons.)
>
> ===================================
> This list is hosted by DevelopMentor(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.