我在尝试对一个由字符串组成的数字数组进行排序,希望按照数值大小排序。
但是问题在于我不能将这些数字转换为整数。
以下是代码:
string[] things= new string[] { "105", "101", "102", "103", "90" };
foreach (var thing in things.OrderBy(x => x))
{
Console.WriteLine(thing);
}
输出:
101, 102, 103, 105, 90
我希望拥有:
我希望:
90, 101, 102, 103, 105
编辑:
输出不能为090, 101, 102...
更新了代码示例,将“sizes
”更改为“things
”。 数组可能像这样:
string[] things= new string[] { "paul", "bob", "lauren", "007", "90" };
这意味着需要按字母和数字进行排序:
007, 90, bob, lauren, paul
image10
应该在image2
之后吗?January
应该在February
之前吗? - svick