复习C#的方法Math.Max和Math.Min
2021-04-23 20:27
                         标签:code   pre   int   console   play   需要   接受   one   tle    温故而知新,今天学习Math.Max和Min的方法。这2个方法,均需要传入2个参数,返回参数中最大值和最小值。     如果用户想在一组数字里,去找出最大值或最小值呢?   Insus.NET的开发习惯,能不用if就不用if。 宣告一个私有属性和一个构造函数,构造函数接受一组数据以及一个输出的方法:   复习C#的方法Math.Max和Math.Min 标签:code   pre   int   console   play   需要   接受   one   tle    原文地址:http://www.cnblogs.com/insus/p/7990908.html


 class Ac
    {
        public void LeanMathFunction()
        {
            int min = Math.Min(5,3);
            Console.WriteLine("5,3最小值Min:{0}",min);
            int max = Math.Max(25,37);
            Console.WriteLine("25,37最大值Max:{0}", max);
        }
    }
程序在控制台运行结果:
此时,你可以参考《几种方法找到整型阵列中的最大值和最小值》http://www.cnblogs.com/insus/p/7975685.html
但是,Insus.NET对链接中这篇的Class4有些变动,用Math.Max和Math.Min去替换大于(>)或小于(
接下来,我们需要测试一下,上面的方法是否正确:

文章标题:复习C#的方法Math.Max和Math.Min
文章链接:http://soscw.com/index.php/essay/78646.html