By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

CaseInsensitiveComparer weirdness

P: n/a
Shouldn't the CaseInsensitiveComparer 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(chars, new System.Collections.CaseInsensitiveComparer());

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

Console.WriteLine(sorted);
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Paul E Collins <fi******************@CL4.org> wrote:
Shouldn't the CaseInsensitiveComparer sort case-insensitively?


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2

P: n/a
"Jon Skeet" <sk***@pobox.com> wrote:
Shouldn't the CaseInsensitiveComparer sort
case-insensitively?


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.


Ah, thanks for clearing that up!

P.
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.