码迷,mamicode.com
首页 > 编程语言 > 详细

C#编程入门--求数组最大值最小值

时间:2017-09-29 11:36:02      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:col   c#   数组   bsp   ati   最小值   for   name   static   

工具类如下:

    public class ArrayHelper
    {
        #region Double数组最大值
        /// <summary>
        /// Double数组最大值
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static double DoubleMax(double[] array)
        {
            if (array == null)
                return 0;
            if (array.Length <= 0)
                return 0;
            double max = array[0];
            for (int i = 1; i < array.Length; i++)
            {
                if (max < array[i])
                {
                    max = array[i];
                }
            }
            return max;
        }
        #endregion

        #region Double数组最小值
        /// <summary>
        /// Double数组最小值
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static double DoubleMin(double[] array)
        {
            if (array == null)
                return 0;
            if (array.Length <= 0)
                return 0;
            double min = array[0];
            for (int i = 1; i < array.Length; i++)
            {
                if (min > array[i])
                {
                    min = array[i];
                }
            }
            return min;
        }
        #endregion

        #region int数组最大值
        /// <summary>
        /// int数组最大值
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static int IntMax(int[] num)
        {
            if (num == null)
                return 0;
            if (num.Length <= 0)
                return 0;
            int a = num[0];
            for (int i = 0; i < num.Length; i++)
            {
                if (a < num[i])
                {
                    a = num[i];
                }
            }
            return a;
        }
        #endregion

        #region int数组最小值
        /// <summary>
        /// int数组最小值
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static int IntMin(int[] num)
        {
            if (num == null)
                return 0;
            if (num.Length <= 0)
                return 0;
            int a = num[0];
            for (int i = 0; i < num.Length; i++)
            {
                if (a > num[i])
                {
                    a = num[i];
                }
            }
            return a;
        }
        #endregion
    }

 

C#编程入门--求数组最大值最小值

标签:col   c#   数组   bsp   ati   最小值   for   name   static   

原文地址:http://www.cnblogs.com/bmbh/p/7610219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!