C# sort Arraylist strings alphabetical and on length

后端 未结 5 727
名媛妹妹
名媛妹妹 2021-01-19 05:14

I\'m trying to sort an ArrayList of String.

Given:

{A,C,AA,B,CC,BB}

Arraylist.Sort gives:

5条回答
  •  无人及你
    2021-01-19 05:49

    I would suggest using the ToArray() method (or just using a List instad of an ArrayList) to take advantage of the OrderBy and ThenBy functions. It would look something like this:

    list = list.OrderBy(/*Order it by length*/).ThenBy(/*Order alphabetically*/);
    

提交回复
热议问题