{
static void Main(string[] args)
{
Program pg = new Program();
int x = 10;
int y = 20;
pg.GetValue(ref x, ref y);
Console.WriteLine("x={0},y={1}", x, y);
Console.ReadLine();
}
public void GetValue(ref int x, ref int y)
{
x = 521;
y = 520;
}
}
{
static void Main(string[] args)
{
Program pg = new Program();
int x=10;
int y=233;
pg.Swap(out x, out y);
Console.WriteLine("x={0},y={1}", x, y);
Console.ReadLine();
}
public void Swap(out int a,out int b)
{
int temp = a; //a,b在函數內部沒有賦初值,則出現錯誤。
a = b;
b = temp;
}
}