c#获取数组中最大数的值

前端技术 2023/09/10 C#

求数组中最大的数的值:
1、数组的max函数:

复制代码 代码如下:

class Program
    {
        static void Main(string[] args)
        {
            int[] array = {1,3,5,2,4,6,7,9,0,8};
           int max= GetMax(array);
            Console.WriteLine(\"数组中最大的值是{0}\",max);
            Console.ReadKey();
        }
        ///
        /// 数组中最大的值
        ///

        ///
        ///
        private static int GetMax(int[] array)
        {
          return array.max();
        }
    }

2、分支语句:

复制代码 代码如下:

class Program
    {
        static void Main(string[] args)
        {
            int[] array = {1,3,5,2,4,6,7,9,0,8};
           int max= GetMax(array);
            Console.WriteLine(\"数组中最大的值是{0}\",max);
            Console.ReadKey();
        }
        ///
        /// 数组中最大的值
        ///

        ///
        ///
        private static int GetMax(int[] array)
        {
            int max = 0;
            for (int i = 0; i             {
                max = max > array[i] ? max : array[i];

            }
            return max;
        }
    }

本文地址:https://www.stayed.cn/item/26532

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。