int[] list ={ 0, 5, 6, 3, 1, 9, 8, 7, 4, 2 };
            Console.WriteLine("排序前:");
            for (int i = 0; i < list.Length; i++)
              {
                    Console.WriteLine(list[i]);
                    //Console.WriteLine();//相当于回车
              }
            Console.WriteLine();
            int temp = 0;
            bool isok = false;
            while (!isok)
            {
                isok = true;
                for (int i = 0; i < 9; i++)//i<list.length-1
                {
                    if (list[i] > list[i + 1])
                    {
                        temp = list[i];
                        list[i] = list[i + 1];
                        list[i + 1] = temp;
                        isok = false;
                    }
                }
            }
            Console.WriteLine("排序后:");
            for (int i = 0; i < list.Length; i++)
            {
                Console.WriteLine(list[i]);
            }问题:list数组里的数值是直接在程序里赋值的,现在我想要在调试里赋值,也就是说我手动把10个数值输入到调试的CMD中,怎么写啊!

解决方案 »

  1.   

    加入下列代码到你代码前面
    Console.WriteLine("Please input number.");
                Console.WriteLine("Enter q to begin running.");
                List<int> inputInts = new List<int>();
                while(true)
                {
                    string input = Console.ReadLine();
                    if (string.Compare(input, "q", true) == 0)
                    {
                        break;
                    }
                    try
                    {
                        int inputInt = int.Parse(input);
                        inputInts.Add(inputInt);
                    }
                    catch
                    {
                        Console.WriteLine("input input number");
                    }
                }            int[] list = inputInts.ToArray();
      

  2.   

    int[] list ={ 0, 5, 6, 3, 1, 9, 8, 7, 4, 2 };
    for(int i = 0; i < list.length; i++) {
        int temp = 0;
        for (int j = 0; j < list.length-i; j++) {
             temp =  list[j];
             list[j] = list[j+1];
             list[j+1] = temp;
       }
    }for(int k = 0; k < list.length; k++) {
        Console.WriteLine(k+"\n");
    }
      

  3.   

    List或数组保存
    int[] a = { 2,5,8,1,7,6 };
                Array.Sort(a);
                for (int i = 0; i < a.Length; i++)
                {
                    Console.Write(a[i].ToString() + " ");            }
                Console.ReadLine();