Re: SortedList - bug or undocumented behavior ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Antonio,
In addition to the other comments:
then '@@', etc...Ascii codes for '?' and '@' are greater than '<' '=' '>'.

Remember .NET stores strings in Unicode, specifically UTF-16. UTF-16 means that the Unicode characters (which can be upto 32-bits) are stored as 16 bit values.

This is an excellent article on the perils & pitfalls of comparing strings in .NET 2.0:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/StringsinNET20.asp

By default strings are compared via the CurrentCulture. It sounds like you are expecting the strings to be compared via ASCII Ordinal, not even Unicode Ordinal.

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


"Antonio Paglia" <tony@xxxxxxxxxxxxxxxx> wrote in message news:evWhNlzAHHA.3380@xxxxxxxxxxxxxxxxxxxxxxx

Hello. I have tried to insert this items into a SortedList.

dic = New SortedList
dic.Add("<<", "<<")
dic.Add("==", "==")
dic.Add(">>", ">>")
dic.Add("@@", "@@")
dic.Add("??", "??")

Debugging this peace of code I have notice that '??' appears as first item, then '@@', etc...Ascii codes for '?' and '@' are greater than '<' '=' '>'. May be this is a bug or an undocumented behavior ??

TIA
Antonio



.



Relevant Pages

  • Re: Some newbie questions - bare with me ;)
    ... This means that the symbol:abc will be ... This is unlike what happens with strings, ... * == this method is used for comparing tow objects basing on their contents. ... def y= value ...
    (comp.lang.ruby)
  • Re: Some optimization tale
    ... >> (and that the right algorithm makes indeed a difference). ... >Since Python does not have pointers, comparing characters within strings ... >requires pulling out the chars as separate strings. ... >truncate prefix to the length of item first. ...
    (comp.lang.python)
  • Re: Mergesort Vs Quicksort
    ... size of a record without comparing two records. ... A contiguous block of strings remains in the orig order. ... The comp function was called 1878269 times. ... recsize was called 3972636 times. ...
    (comp.programming)
  • Re: Some optimization tale
    ... A common surprise. ... Since Python does not have pointers, comparing characters within strings ... truncate prefix to the length of item first. ...
    (comp.lang.python)
  • Re: sorting dates
    ... >comparing strings no doubt takes longer than comparing numbers. ... so, for strings of the length in question, ISTM ... >"digits" should be hexadecimal, but for sorting purposes, decimal digits ... The string 'YYYYMMDD' is "Basic format". ...
    (comp.lang.javascript)