Code Snippet - Minimum and Maximum Values of an Array

This method will take in an array of type double and return the minimum and maximum values. I wrote it to deal with temperature readings and to find the min/max for a week.

It will work with any number of array elements as it uses a foreach loop to iterate through the values and assign the smallest and largest values to a new array to be returned.

///<summary>
///
///</summary>
/// <param name=""></param>
/// <returns></returns>
public static double[] MinMax(double[] values)
{
        double[] minMax = new double[2];

        minMax[0] = values[0];
        minMax[1] = values[0];
        
        //output array will have the minumim as the first value and the maximum as the second
        foreach(double d in values)
        {      
               //checks current value of minMax[0] against value of d and sets it to d if smaller
               if(dminMax[1])
               { 
                      minMax[1]= d;
               }         
       }
       return minMax;
}

You might think it odd that I did not use an if-else block, but not using one is important because It allows the min and max to be the same value which would be required if all of the array elements are the same, with an if-else statement the second if statement would be passed over if the first evaluates to true.