String.Compareto Strangeness

  • Thread starter Thread starter Gerry Wheeler
  • Start date Start date
G

Gerry Wheeler

I've written a very simple C# program (console type) that accepts two args,
compares them, and displays the result. Here is some of what I get...

'a' > '-'
'b' > '-'
'c' > '-'
'aaa' > 'a-a'
'abc' < 'a-c'

(I retyped this from memory, as I couldn't post it from the office.)

Can anyone explain that last one to me? It seems to be an anomoly. I was
originally thinking it might have to do with the locale and culture and
stuff, but it seems just plain inconsistent.
 
In VB, immediate mode, same result.

? "aaa" > "a-a"
True
?"abc" > "a-c"
False

' however,
?"acc">"a-c"
True

'----------------------------------
 
I found an alternative. The static method String.CompareOrdinal does what I
want. The String.Compareto method is affected by the culture settings. It
still seems strange to me -- in this culture I don't know who would sort
their strings that way.
 
Back
Top