Min value from number array - CSharp System

CSharp examples for System:Array Calculation

Description

Min value from number array

Demo Code

/// Department of Proteomics and Signal Transduction. All rights reserved.
using System.Collections.Generic;
using System;//from   w  w w. j  a v a2  s. c o m

public class Main{
        public static int Min(int[] x)
        {
            int n = x.Length;
            if (n == 0)
            {
                return Int32.MaxValue;
            }
            int min = Int32.MaxValue;
            for (int i = 0; i < n; i++)
            {
                int val = x[i];
                if (val < min)
                {
                    min = val;
                }
            }
            return min;
        }
        public static double Min(double[] x)
        {
            int n = x.Length;
            if (n == 0)
            {
                return Double.NaN;
            }
            double min = Double.MaxValue;
            for (int i = 0; i < n; i++)
            {
                double val = x[i];
                if (val < min)
                {
                    min = val;
                }
            }
            return min;
        }
}

Related Tutorials