Return the minimum value of several values - CSharp System

CSharp examples for System:Math Number

Description

Return the minimum value of several values

Demo Code

/// A port of the LoDMath static member class written in AS3 under the MIT license agreement.
using System.Linq;
using System.Collections.Generic;
using System;/*from w  ww  .j  a  va  2  s. c  om*/

public class Main{
        /// <summary>
        /// Return the minimum value of several values
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static double Min(params double[] args)
        {
            if (args.Length == 0)
                return double.NaN;
            double value = args[0];

            for (int i = 0; i <= args.Length - 1; i++)
            {
                if (args[i] < value)
                    value = args[i];
            }

            return value;
        }
}

Related Tutorials