Why does “-less” sort after “hello” instead of before it?

后端 未结 4 1287
心在旅途
心在旅途 2021-01-05 17:19

I\'m seeing some very strange sorting behaviour using CaseInsensitiveComparer.DefaultInvariant. Words that start with a leading hyphen \"-\" end up sorted as if the hyphen w

4条回答
  •  清歌不尽
    2021-01-05 17:29

    Sort order is dependent on the culture, so you can't assume characters will sort in ASCII order.

    http://msdn.microsoft.com/en-us/library/a7zyyk0c.aspx

    In your example, "h" (U+0048) is before "dash" (U+2013), so "hello" will appear before "-less". "." (U+002E) is before both, so ".net" appears first.

提交回复
热议问题