抱歉,我刚开始学习LINQ,如果你能说使用Linq按 ID 或 BonusCount
string[] res; // {"ID,Name, BonusCount",etc}
res = new string[] {"1, Mark, 250", "4, Ostin, 150","2, Rick K., 12","11,Robert,1"};
我会得到: 由id:
{"1, Mark, 250", "2, Rick K., 12", "4, Ostin, 150","11,Robert,1"};
by BonusCount:
{"11,Robert,1", "2, Rick K., 12", "4, Ostin, 150", "1, Mark, 250"};I
有可能吗?提前谢谢!
答案 0 :(得分:10)
是的,这是可能的,非常容易
var res = new string[] { "1, Mark, 250", "4, Ostin, 150", "2, Rick K., 12", "11,Robert,1" };
var sortByBonus = res.OrderBy(i => int.Parse(i.Split(',').Last())).ToArray();
var sortById = res.OrderBy(i => int.Parse(i.Split(',').First())).ToArray();