using System; using System.Collections.Generic; using System.Linq; namespace TestApp { class Program { public class Player { public string Position { get; set; } public string Name { get; set; } public int Salary { get; set; } public int Age { get; set; } } static void Main(string[] args) { List players = new List() { new Player() { Name = "Peyton Manning", Age = 36, Position = "QB", Salary = 19000000 }, new Player() { Name = "Tom Brady", Age = 35, Position = "QB", Salary = 18400000 }, new Player() { Name = "Drew Brees", Age = 34, Position = "QB", Salary = 21000000 }, new Player() { Name = "Randy Moss", Age = 35, Position = "WR", Salary = 7000000 }, new Player() { Name = "Marvin Harrison", Age = 38, Position = "WR", Salary = 11000000 }, new Player() { Name = "Demaryius Thomas", Age = 23, Position = "WR", Salary = 5000000 }, new Player() { Name = "Ryan Clady", Age = 26, Position = "OT", Salary = 10000000 }, }; var highestPaidPlayers = from pl in players group pl by pl.Position into g let max = g.Max(x => x.Salary) let maxPl = g.Where(x => x.Salary == max).First() select maxPl; var highestPaidPlayers2 = players.GroupBy(p => p.Position).Select(x => x.Where(p => p.Salary == x.Max(m => m.Salary)).First()); foreach (Player player in highestPaidPlayers) { Console.WriteLine("The highest paid {0} is {1}, who is being paid {2}", player.Position, player.Name, player.Salary); } System.Console.WriteLine("-----------"); foreach (Player player in highestPaidPlayers2) { Console.WriteLine("The highest paid {0} is {1}, who is being paid {2}", player.Position, player.Name, player.Salary); } } } }