比如我定义了一个类:
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]中的数据调换,需要再从新写一个类吗?
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]中的数据调换,需要再从新写一个类吗?
temp=pro[2];
pro[2]=pro[3];
pro[3]=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();