数组列表最初包含以下值:
对数组列表项进行排序。
[0]: N8
[1]: N4
[2]: N10
[3]: N11
[4]: N13
[5]: N0
[6]: N3
[7]: N2
[8]: N9
[9]: N6
[10]: N12
[11]: N1
[12]: N5
[13]: N7
现在我需要对数组列表进行排序,使其变为
[0]: N0
[1]: N1
[2]: N2
[3]: N3
[4]: N4
[5]: N5
[6]: N6
[7]: N4
[8]: N8
[9]: N9
[10]: N10
[11]: N11
[12]: N12
[13]: N13
答案 0 :(得分:1)
使用LINQ OrderBy
:
string[] array = {"N8","N4","N10","N11","N13","N0","N3","N2","N9","N6","N12","N1","N5", "N7" };
var result = array.OrderBy(x => Convert.ToInt32(x.Substring(1))).ToArray();