This post will discuss how to find the minimum and maximum number from an array in C#.

1. Using Linq

A simple solution to find the minimum and maximum value in a sequence of values is using the Enumerable.Min and Enumerable.Max methods from the System.Linq namespace.

Download  Run Code

Output:

Minimum number is -1
Maximum number is 8

2. Using Array.Sort() Method

Another plausible, but less recommended way to find the minimum/maximum of an array is to sort the array in ascending order. Then the first and last element of the sorted array would the minimum and the maximum element, respectively.

Download  Run Code

Output:

Minimum number is -1
Maximum number is 8

3. Using Custom Routine

Finally, we can write a custom routine for finding the minimum and the maximum number of an array. The idea is to traverse the array and keep track of the minimum or maximum value found so far. Here’s what the code would look like:

Download  Run Code

Output:

Minimum number is -1
Maximum number is 8

That’s all about finding the minimum and maximum number from an array in C#.