0
   string[] words = { "aaaa", "a-aaa", "bbbb", "b-bbbb", "000"};
   var sortedWords =
            from w in words
            orderby w
            select w;

When I run this query the expected order is 000, a-aaa,aaaa,b-bbbb and bbbb.

But the actual result is 000, aaaa,a-aaa,bbbb and b-bbbb.

I verified with SQL server its giving same as LINQ result. Is my understanding wrong or is it a bug?

Thanks in Advance.

Massimiliano
  • 16,770
  • 10
  • 69
  • 112
Yass
  • 592
  • 1
  • 8
  • 30

1 Answers1

1

Take a look at this answer for the related question. Hyphen is a special case when you sort strings with default culture-specific comparer.

Community
  • 1
  • 1
Massimiliano
  • 16,770
  • 10
  • 69
  • 112
  • thank you. This solution doesn't suit for all scenarios. For example, if you are writing SharePoint CAML query then applying this solution doesn't work well. – Yass Feb 22 '12 at 04:04
  • @Yass: so are you trying to write a query in CAML? what is the question? – Massimiliano Feb 22 '12 at 08:05
  • yes, as i mentioned earlier, i tried in SQL server as well as in CAML query, both return the same values.If we have to implement culture specific sorting, i feel its complicated. – Yass Feb 23 '12 at 22:39