我有这个密码
Person[] peopleArray = new Person[5]
{
new Person("John", "Jones", "001", 1450),
new Person("Jimmy", "Smith", "004", 1237),
new Person("Sue", "Baker", "002", 1534),
new Person("Chuck", "Smith", "003", 1450),
new Person("Toby", "Jones", "005", 1450)
};
var sortedPeopleList = peopleArray.OrderBy(a => a.score).ThenBy(a => a.lastName)
.ThenBy(a => a.firstName).Reverse();
foreach (Person p in sortedPeopleList)
Console.WriteLine(p.score + " " + p.id + " " + p.firstName + " " + p.lastName );
Console.ReadKey();产出如下:
1534 002苏贝克 1450 003查克史密斯<=这应该是#4 1450 005托比琼斯<=这应该是#3 1450 001约翰·琼斯<=这应该是#2 1237 004 Jimmy Smith
所需输出必须按分数(降序)排序,然后按姓氏(升序),最后按姓氏(升序)排序。
1
534 002苏贝克 1450 001约翰琼斯 1450 005托比琼斯 1450 003查克·史密斯 1237 004 Jimmy Smith
任何建议都会有帮助。谢谢!
发布于 2015-03-04 00:49:48
OrderBy和ThenBy都有合作伙伴方法OrderByDescending和ThenByDescending。
因此,现在您可以消除Reverse并使用:
peopleArray.OrderByDescending(a => a.score)
.ThenBy(a => a.lastName)
.ThenBy(a => a.firstName);https://stackoverflow.com/questions/28844757
复制相似问题