C# LINQ — “Min”/“Max”

LINQ (Language-Integrated Query) is a set of integrated C# capabilities which allow queries against data.

Vincent Taylor
Jan 11, 2022

Today’s Objective: Demonstrate the Min and Max methods of LINQ to get the minimum and maximum numerical values from a data collection.

The Min/Max Methods:

Simple C# LINQ methods used to identify the lowest and highest numerical values in a data collection.

Microsoft Documentation for “Min” / Microsoft Documentation for “Max”

An Example:

Without LINQ, you may use code similar to this to find the minimum or maximum value:

But by using LINQ, you can simply write:

Like most LINQ methods, it also works for custom data types that are not numeric, but contain numeric variables:

--

--

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.