定义一个数组用来存放数据:
public static int[] a = new int[20];max(),min(),函数均已实现定义形式为:public static int max(params int[] args);
            public static int min(params int[] args);在主函数中写道:Console.WriteLine("{0}", max(1, 2, 3, 4, 2, 1, 6, 9, 4));
                Console.WriteLine("{0}", min(1, 2, 3, 4, 2, 1, 6, 9, 4));则结果正确:9      1
但是在主函数写道:
        for (int i = 0; i < 5; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine("{0}", max(a));
        Console.WriteLine("{0}", min(a));
输入1, 2, 3, 4, 2结果却为  4       0
说明max()函数应经调用成功,但是min()函数却没有被调用、
定义的这些东西,和主函数都在同一个类中class App{};试了好多次都只这样,为什么???
求高人指点!~!~!~!~!~!

解决方案 »

  1.   

    static void Main(string[] args)
    {
        //Console.WriteLine("{0}", max(1, 2, 3, 4, 2, 1, 6, 9, 4));
        //Console.WriteLine("{0}", min(1, 2, 3, 4, 2, 1, 6, 9, 4));
        int[] a = new int[5];
        for (int i = 0; i < 5; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine("{0}", max(a));
        Console.WriteLine("{0}", min(a));
        Console.ReadKey();
    }public static int max(params int[] args)
    {
        return args.Max();
    }
    public static int min(params int[] args)
    {
        return args.Min();
    }
    依次输入:
    1
    2
    3
    4
    2
    正常。
    输出
    4
    1
      

  2.   

    class App
    {
        public static int[] a = new int[20];
        public static int Sort_Max(params int[] args)
        {
            int max, i, j, temp;        //冒泡法比较大小
            for (i = 0; i < (args.Length - 1); i++)
            {
                for (j = i + 1; j < args.Length; j++)
                {
                    if (args[i] < args[j])
                    {
                        temp = args[i];
                        args[i] = args[j];
                        args[j] = temp;
                    }
                }
            }
            max = args[0];        return max;
        }    public static int Sort_Min(params int[] args)
        {
            int min, i, j, temp;        for (i = 0; i < (args.Length - 1); i++)
            {
                for (j = i + 1; j < args.Length; j++)
                {
                    if (args[i] < args[j])
                    {
                        temp = args[i];
                        args[i] = args[j];
                        args[j] = temp;
                    }
                }
            }        min = args[(args.Length - 1)];
            return min;
        }    public static void Main()
        {
            //Console.WriteLine("{0}", Sort_Max(1, 2, 3, 4, 2, 1, 6, 9, 4));
            //Console.WriteLine("{0}", Sort_Min(1, 2, 3, 4, 2, 1, 6, 9, 4));        for (int i = 0; i < 5; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("{0}", Sort_Max(a));
            Console.WriteLine("{0}", Sort_Min(a));
            Console.ReadLine();
        }
    }
    我改了、不成啊啊、这是我的程序、坐等高手!~!~!我是新手、才开始自学、太深奥的话,不懂
      

  3.   

    你声明的数组太长了。里面有很多0.尝试吧public static int[] a = new int[20];
    改为
    public static int[] a = new int[5];
      

  4.   


    这个没想到、对了,谢谢、我是新手、假如碰到这种问题,在MSDN上该怎么搜索?????
      

  5.   

    这种问题,细心才行。msdn上没办法。