Reputation:
sorry I just started learning LINQ, and I would be glad if you would say it is possible to do using Linq sort this array by ID or BonusCount
string[] res; // {"ID,Name, BonusCount",etc}
res = new string[] {"1, Mark, 250", "4, Ostin, 150","2, Rick K., 12","11,Robert,1"};
I would get: by 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
Is it possible? Thanks in advance!
Upvotes: 4
Views: 903
Reputation: 7836
Yes it is possible and quite easy
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();
Upvotes: 10