Accepted answer

if a player name should only appear once you have to group the collection by player and order each group by score. then you can pick the highest 3.

var top3 = scores.groupby(x => x.player)
                 .select(x => x.orderbydescending(y => y.score).first())
                 .orderbydescending(x => x.score)
                 .thenby(x => x.player)


scores.groupby(i => i.player)
      .select(g => g.orderbydescending(s => s.score).first())
      .orderbydescending(i => i.score)
      .thenby(i => i.player)

but there is a bonus up-vote for any solution that puts the person whose name appears first in the alphabet highest in the event that their scores are tied

thenby is used for tie-breaks on ordering.

idea is to group by player to get each players best score and then process that flat list.


you can group them and then pick the maximum score of each player, and then order them:

var top3 = scores.groupby(x=>x.player)
                 .orderbydescending(s => s.score)

Related Query

More Query from same tag