Sum, Min, and Max Methods

Learn how to use the Sum, Min, and Max methods.

So far, we’ve worked with collections of any type. We’ve used a collection of movies, or non-numerals, in our examples. Let’s learn three methods to work with collections of numbers.

How to find the minimum and maximum of a collection

The Sum, Min, and Max methods return the sum, minimum, and maximum of a collection of numbers, respectively. These three methods receive a delegate returning a number as a parameter.

For the following example, let’s change our Movie class to contain the film duration in minutes. Then let’s find our total watch time, and the shortest and the longest film by duration.

Get hands-on with 1000+ tech skills courses.