小弟刚学编程,求3个数比较大小的代码,要经过测试的.

解决方案 »

  1.   

    public int getMax(int a, int b, int c)
    {
        return a>b && a>c ? a : b > c ? b : c;
    }返回三个数中,最大的一个
      

  2.   

           public int MaxNumber(int a, int b, int c)
            {
                if (a > b && a > c)
                {
                    return a;
                }
                else if (b > a && b > c)
                {
                    return b;
                }
                else
                {
                    return c;
                }
            }
      

  3.   

    private int getMax(int a, int b, int c)
            {
                int[] array=new int[]{a,b,c};
                Array.Sort(array);
                return array[array.Length-1];        }
    返回最大的那个
      

  4.   


    using System;
    using System.Collections.Generic;
    using System.Text;namespace CompareValue
    {
        class Program
        {
            static void Main(string[] args)
            {
                int a = 1, b = 2, c = 3;
                Console.WriteLine(a > b && a > c ? a : b > c ? b : c);
                Console.ReadKey();
            }
            public int getMax(int a, int b, int c)
            {
                return a > b && a > c ? a : b > c ? b : c;
            }
        }
    }
      

  5.   


    using System;
    using System.Collections.Generic;
    using System.Text;namespace CompareValue
    {
        class Program
        {
            static void Main(string[] args)
            {
                int a = 1, b = 2, c = 3;
                Console.WriteLine(a > b && a > c ? a : b > c ? b : c);
                Console.ReadKey();
            }
        }
    }10楼代码有垃圾,看现在的
      

  6.   

    int[] arr = new int[] { 20, 1, 15 };
    var max = from n in arr orderby n select n;
    foreach (var n in max)
    {
        Console.WriteLine(n.ToString());
    }
    /*
    1
    15
    20
    请按任意键继续. . .
    */