1. 程式人生 > >C#語言————兩值交換

C#語言————兩值交換

//兩值交換
public static void Show(ref int num1,ref int num2)
{
int num=num1;
num1=num2;
num2=num;
}

static void Mian(string [] args)
{
int num1=7;
int num2=4;
console.WritLine("交換前,num1:{0},num2:{1}",num1,num2);
Show(ref num1,ref num2);
console.WritLine("交換前,num1:{0},num2:{1}",num1,num2);
}