Return the maximum of several values - CSharp System

CSharp examples for System:Math Number

Description

Return the maximum 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   ww  w  .  java  2s .  c om*/

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

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

            return value;
        }
}

Related Tutorials