a,b交换
方法一:
int a=10;
int b=5;
int temp;
temp =a;
a=b;
b=temp;
方法二:
int a = 1; //0001
int b = 2; //0010
a = a+b;
b=a-b;
a=a-b;
方法三:
int a = 1; //0001
int b = 2; //0010//
a = a^b; //0011
b=a^b; //0001
a=a^b; //0010
方法四:调用
public static void Main(string[] args)
{
swap( ref a, ref b);
Console.WriteLine("a:"+a+" b:"+b);
Console.ReadKey();
}
public static void swap(ref int a,ref int b)
{
a = a^b; //0011
b=a^b; //0001
a=a^b; //0010
}