String sorting issue in C#

前端 未结 3 1802
逝去的感伤
逝去的感伤 2020-11-27 07:28

I have List like this

    List items = new List();
    items.Add(\"-\");
    items.Add(\".\");
    items.Add(\"a-\");
    items.A         


        
3条回答
  •  孤独总比滥情好
    2020-11-27 08:14

    If you want your string sort to be based on the actual byte value as opposed to the rules defined by the current culture you can sort by Ordinal:

    items.Sort(StringComparer.Ordinal);

    This will make the results consistent across all cultures (but it will produce unintuitive sortings of "14" coming before "9" which may or may not be what you're looking for).

提交回复
热议问题