How can I employ Linq to select Top value from each group
when I have a code segment like :
var teams = new Team[]
{
new Team{PlayerName=\"Ricky\
I would suggest you first implement an extension method on the IEnumerbale class called Top For example:
IEnumerable Top(this IEnumerable target, Func keySelector, int topCount)
{
return target.OrderBy(i => keySelector(i)).Take(topCount);
}
Then you can write:
teams.GroupBy(team => team.TeamName).Top(team => team.PlayerScore, 1).
There might be some slight modifications to make it compile.