Finds the maximum value in the specified 2D array (NaN values not included). - CSharp System

CSharp examples for System:Array Find

Description

Finds the maximum value in the specified 2D array (NaN values not included).

Demo Code



public class Main{
        /// <summary>
        /// Finds the maximum value in the specified 2D array (NaN values not included).
        /// </summary>
        /// <param name="array">The array.</param>
        /// <returns>The maximum value.</returns>
        public static double Max2D(this double[,] array)
        {/*w  w  w  .  j  a va  2  s .co  m*/
            var max = double.MinValue;
            for (var i = 0; i < array.GetLength(0); i++)
            {
                for (var j = 0; j < array.GetLength(1); j++)
                {
                    if (array[i, j].CompareTo(max) > 0)
                    {
                        max = array[i, j];
                    }
                }
            }

            return max;
        }
}

Related Tutorials