String compare not always transitive - by Marc Gravell

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


14
0
Sign in
to vote
ID 236900 Comments
Status Closed Workarounds
Type Bug Repros 11
Opened 11/9/2006 7:32:19 AM
Access Restriction Public

Description

String compare (default compare) is not always transitive; if the string has multiple symbols (e.g. hyphens) it can start looping in the compare - i.e. a > b > c > a.
Ordinal compare is fine, but is not the default.
Affects 1.1 and 2.0

IMPORTANT: Note that this demonstrably breaks Sort() using the default comparer. There is also an example of this breaking SortedList such that it cannot find items that *are there*. It could also break any user code that does a sort / compare for any reason (grouping, uniqueness, etc).

[originally reported by William Hooper on microsoft.public.dotnet.languages.csharp]
[MG edit: tidied steps / results]
Sign in to post a comment.
Posted by Mark Hurd on 5/10/2010 at 7:15 PM
I also see in .NET 4.0
Console.WriteLine(s1.CompareTo(s3))
Console.WriteLine(s3.CompareTo(s2))
Console.WriteLine(s1.CompareTo(s2))
outputs 1 1 1 i.e. transitive
compared to .NET 2.0 (3.5) -1 -1 1 not transitive.
Posted by BlueRaja on 5/6/2010 at 2:08 PM
This appears to be fixed in .Net 4.0 (at least for the examples given)
Posted by Marc Gravell on 11/27/2006 at 10:10 PM
They dared
Posted by Marc C Brooks on 11/16/2006 at 2:44 PM
Don't you DARE close this without fixing like you did with TypeConverter.IsValid.