首先定义一个类
class Test
{
public int num;
}
然后写方法
static void Switch(Test a, Test b)
{
int c = a.num;
a.num = b.num;
b.num = c;
}
最后在主函数new出两个test类,将数值赋给test().num,然后调用方法
Test x = new Test();
x.num = 10;
Test y = new Test();
y.num = 20;
Switch(x, y);
Console.WriteLine(x.num);
Console.ReadKey();
输出的结果是x.num = 20 ,
y.num = 10;