1
我需要按點數排序,然後按職位排列。我如何通過職位列表屬性訂購我的列表?按名單排列的訂單清單<int>財產
public class Sailor
{
public string Name { get; set; }
public int Points { get; set; }
public List<int> Positions { get; set; }
public Sailor(string name, int points, List<int> positions)
{
Name = name;
Points = points;
Positions = positions;
}
}
var sailors = new List<Sailor>
{
new Sailor("Carl", 20, new List<int> { 2, 2, 4, 1, 1 }),
new Sailor("Paul", 10, new List<int> { 4, 5, 3, 2, 5 }),
new Sailor("Anna", 20, new List<int> { 1, 1, 1, 3, 4 }),
new Sailor("Lisa", 11, new List<int> { 3, 4, 5, 5, 2 }),
new Sailor("Otto", 11, new List<int> { 5, 3, 2, 4, 3 })
};
foreach (var sailor in sailors)
{
sailor.Positions.Sort();
}
var orderedListOfSailors = sailors.OrderByDescending(x => x.Points);
這給了我:
Carl, Anna, Lisa, Otto, Paul
我希望它是:
Anna, Carl, Otto, Lisa, Paul
爲什麼?因爲安娜有3個第一個地方,卡爾有2奧托具有2,3,3,莉莎有2個,3個,4