Min among values - CSharp System

CSharp examples for System:Math Number

Description

Min among values

Demo Code

// Copyright (c) Cragon. All rights reserved.
using System;/*  ww  w. ja  va 2 s .  c o m*/

public class Main{
        //---------------------------------------------------------------------
        public static int Min(params int[] values)
        {
            int length = values.Length;
            if (length == 0)
            {
                return 0;
            }
            int num2 = values[0];
            for (int i = 1; i < length; i++)
            {
                if (values[i] < num2)
                {
                    num2 = values[i];
                }
            }
            return num2;
        }
        //---------------------------------------------------------------------
        public static float Min(params float[] values)
        {
            int length = values.Length;
            if (length == 0)
            {
                return 0f;
            }
            float num2 = values[0];
            for (int i = 1; i < length; i++)
            {
                if (values[i] < num2)
                {
                    num2 = values[i];
                }
            }
            return num2;
        }
        //---------------------------------------------------------------------
        public static ulong Min(ulong a, ulong b)
        {
            return ((a >= b) ? b : a);
        }
        //---------------------------------------------------------------------
        public static long Min(long a, long b)
        {
            return ((a >= b) ? b : a);
        }
        //---------------------------------------------------------------------
        public static uint Min(uint a, uint b)
        {
            return ((a >= b) ? b : a);
        }
        //---------------------------------------------------------------------
        public static int Min(int a, int b)
        {
            return ((a >= b) ? b : a);
        }
        //---------------------------------------------------------------------
        public static ushort Min(ushort a, ushort b)
        {
            return ((a >= b) ? b : a);
        }
        //---------------------------------------------------------------------
        //public static Int8 Min(Int8 a, Int8 b)
        //{
        //    return ((a >= b) ? b : a);
        //}

        //---------------------------------------------------------------------
        //public static UInt8 Min(UInt8 a, UInt8 b)
        //{
        //    return ((a >= b) ? b : a);
        //}

        //---------------------------------------------------------------------
        public static short Min(short a, short b)
        {
            return ((a >= b) ? b : a);
        }
        //---------------------------------------------------------------------
        public static float Min(float a, float b)
        {
            return ((a >= b) ? b : a);
        }
}

Related Tutorials