类A里的功能都不能用,是不是传值不成功啊!
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace shuzu
{
    class A
    {
       public int[] p=new int[5];
        public void paixu(int[] arr)//排序功能
        {
            for (int i = 0; i < p.Length; i++)
            {
                for (int j = i + 1; j < p.Length; j++)
                    if (p[i] > p[j])
                    {
                        int t = p[i];
                        p[i] = p[j];
                        p[j] = t;
                    }
                Console.WriteLine("{0}", p[i]);
            }
        }
        public void chazhao(int[] arr)//查找功能
        {
            string t = Console.ReadLine();
            int L = Convert.ToInt32(t);
            int i = 0;
            int j = p.Length;
            while (L < (i + j) / 2)
            {
                j = (j + i) / 2 - 1;
            }
            while (L > (i + j) / 2)
            {
                i = (j + i) / 2 + 1;
            }
            if (i > j)
                Console.WriteLine("没有这个元素");
            else
                Console.WriteLine("{0}", (i + j) / 2);
        }
        public void qiuhe(int[] arr)//求和
        {
            int mux=0;
            for(int i=0;i<p.Length;i++)
                mux +=p[i];
            Console.WriteLine("{0}", mux);
        }    }
    class Program
    {
      public  static void Main()
        {
            string[] str = new string[5];
            int[] arr = new int[5];
            for (int i = 0; i < 5; i++)
            {
                str[i] = Console.ReadLine();
                arr[i] = Convert.ToInt32(str[i]);
            }
            A sz = new A();
            Console.WriteLine(" 1=paixu 2=chazhao 3=qiuhe");
            Console.Write("Please enter your selection: ");                   sz.paixu(arr);                   sz.chazhao(arr);                    sz.qiuhe(arr);           Console.ReadLine();
      }
 
  }
}

解决方案 »

  1.   

    大致看了下,基本思路是差不多,
    1 手工输入数组长度,或定长如5个元素;
    2 可直接使用ArrayList的Sort直接排序;
    3 LZ这种做法,在类中不需要定义数组属性,直接赋值再调用相应方法即可;
    4 调试程序对理解代码非常有帮助,即使是自己写的代码;
      

  2.   

    编译错误还是执行错误?=============== 
    汶川赈灾:http://finance.sina.com.cn/roll/20080516/15384878376.shtml
      

  3.   

            public void paixu(int[] arr)//排序功能 
            { 
                for (int i = 0; i  < p.Length; i++) 
                { 
                    for (int j = i + 1; j  < p.Length; j++) 
                        if (p[i] > p[j]) 
                        { 
                            int t = p[i]; 
                            p[i] = p[j]; 
                            p[j] = t; 
                        } 
                    Console.WriteLine("{0}", p[i]); 
                } 
            } 
    =========================================================
    你传的是arr,结果代码里面用的是数组p