CaseInsensitiveComparer weirdness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul E Collins

    #1

    CaseInsensitiveComparer weirdness

    Shouldn't the CaseInsensitive Comparer sort case-insensitively?

    The following code prints out 'AZaz', which indicates a case-sensitive sort.
    What do I need to do to perform a case-insensitive sort ('AaZz')?

    char[] chars = new char[] { 'A', 'z', 'a', 'Z' };
    string sorted = "";

    Array.Sort(char s, new System.Collecti ons.CaseInsensi tiveComparer()) ;

    for (int i = 0; i < chars.Length; i++)
    {
    sorted += chars[i];
    }

    Console.WriteLi ne(sorted);


  • Jon Skeet

    #2
    Re: CaseInsensitive Comparer weirdness

    Paul E Collins <find_my_real_a ddress@CL4.org> wrote:[color=blue]
    > Shouldn't the CaseInsensitive Comparer sort case-insensitively?[/color]

    It should, and it does - for strings. It doesn't compare characters. If
    you change your sample to use strings instead of chars, it works fine.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Paul E Collins

      #3
      Re: CaseInsensitive Comparer weirdness

      "Jon Skeet" <skeet@pobox.co m> wrote:
      [color=blue][color=green]
      > > Shouldn't the CaseInsensitive Comparer sort
      > > case-insensitively?[/color]
      >
      > It should, and it does - for strings. It doesn't
      > compare characters. If you change your sample
      > to use strings instead of chars, it works fine.[/color]

      Ah, thanks for clearing that up!

      P.


      Comment

      Working...