MaxBy and MinBy: New LINQ extensions series — Maytham Fahmi

public class GameWinner
{
public GameWinner(string name, int rank, int point)
{
Name = name;
Rank = rank;
Point = point;
}
public string Name { get; set; }
public int Rank { get; set; }
public int Point { get; set; }
}
var gameWinners = new List<GameWinner>
{
new ("John", 1, 99),
new ("Peter", 3, 95),
new ("Mick", 2, 96)
};
var highestPoint = gameWinners.MaxBy(e => e.Point);
var lowestPoint = gameWinners.MinBy(e => e.Point);
Console.WriteLine($"{highestPoint?.Name} has highest point {highestPoint?.Point}");
Console.WriteLine($"{lowestPoint?.Name} has highest point {lowestPoint?.Point}");
John has highest point 99
Peter has highest point 95

--

--

Maytham is a passionate software developer with more than ten years of experience. His motivation is to help transform ideas into production ready systems.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store