for (int j=1;j <=a.Length;j++)   这句数组超了...是排序么?呀 你那个排的好像不对吧..好像结果不对.试试我这个.
    int[] a = new int[] { 2, 5, 6, 1, 30, 3 };
            int b;
            for(int i=0; i<a.Length-1; i++)
            {
                for(int j=i+1; j<a.Length; j++)
                {
                    if(a[i]<a[j])
                    {
                        b=a[i]; 
                        a[i]=a[j]; 
                        a[j]=b; 
                    }
}
                }
            for (int i = 0; i < a.Length; i++)
            {
                Console.BackgroundColor = ConsoleColor.Yellow;
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("{0}", a[i]);
            }
            Console.Read();

解决方案 »

  1.   

    for (int j=1;j <=a.Length;j++) //数组超出索引
      for (int i = 0; i  < a.Length - 1; i++) 
                {  
                    for (int j=1;j <a.Length;j++) 
                    { 
                        b = a[j]; 
                        a[j] = a[i]; 
                        a[i] = b; 
                    } 
                } 
      

  2.   

        int[] a = new int[] { 2, 5, 6, 1, 30, 3 };
        int k = 0;
        bool flag = false;
        for(int i=0; i<a.Length-1; i++)
        {
            k = i;
            flag = true;
            for(int j=i+1; j<a.Length; j++)
            {
                if(a[k]<a[j])
                {
                    k = j;
                    flag = false;
                }
            }
            if (flag) break;
            if (i != k)
            {
                a[i] = a[i] + a[k];
                a[k] = a[i] - a[k];
                a[i] = a[i] - a[k];
            }
         }
         for (int i = 0; i < a.Length; i++)
         {
             Console.BackgroundColor = ConsoleColor.Yellow;
             Console.ForegroundColor = ConsoleColor.Magenta;
             Console.Write("{0}", a[i]);
         }
         Console.Read();
      

  3.   


                for (int i = 0; i  <= a.Length - 1; i++) 
                {  
                    for (int j=1;j <=a.Length;j++) 
                    { 
                        b = a[j]; 
                        a[j] = a[i]; 
                        a[i] = b; 
                    } 
                } 哪里有比较?
    索引是从o开始到长度-1结束