class Program
{
static void Main(string[] args)
{
int a = 8, b = 2;
Program.exchange1(ref a, ref b);
Console.Write("a:{0},b:{1}", a, b);
}
private static void exchange1(ref int a, ref int b)
{
a = a + b;
b = a - b;
a = a - b;
}
private static void exchange2(ref int a, ref int b)
{
a = a - b;
b = a + b;
a = b - a;
}
private static void exchange3(ref int a, ref int b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
} |