比如我定义了一个类:
    class process      //进程信息
    {
        private string _Processname = "";
        private int _Arrivetime;
        private int _Servetime;
        private int _Finishtime;
        private double _Arrangetime;
        private double _Valuetime;
        ...私有变量的属性
   }
 process[] pro = new process[num];
实例化之后,想要实现类数组中的数据交换swap(),
比如把pro[2]和pro[3]中的数据调换,需要再从新写一个类吗?

解决方案 »

  1.   

    不用啊直接定义一个temp中间变量 交换就好了啊
      

  2.   

    process temp;
    temp=pro[2];
    pro[2]=pro[3];
    pro[3]=temp;
      

  3.   

    swap的机制就是通过一个临时中间对像来对两个对像的值进行调换。而且std::swap只能操作字串。你可以自己重新写一个swap方法,但没有必要,如 3 楼的方式就很好
      

  4.   

    :设中间变量TEMP
     int[] a = new int[2]{ 100, 200 };
                int temp;
               temp = a[1];
               a[1] = a[0];
               a[0] = temp;
                Console.WriteLine("{0},{1}",a[0],a[1]);
               Console.Read();
    随便告诉你一个翻转数组的方法:
    要首先引入一个命名空间using System.Collections;
    主要代码:
                  ArrayList al = new System.Collections.ArrayList();
                al.Add(0);
                al.Add(1);
                al.Add(2);
                al.Add(3);
                al.Add(4);
                al.Add(5);
                Console.WriteLine("原数组为");
                for (int i = 0; i < al.Count; i++)
                {
                    Console.WriteLine(al[i]);            }
                al.Reverse();//反转数组,实现交换                       Console.WriteLine("反转后的数组为");
                for (int i = 0; i < al.Count; i++)
                {
                    Console.WriteLine(al[i]);
                    
                }
                Console.ReadLine();