本帖最后由 y494890511 于 2013-11-6 07:36 编辑
嘿嘿不好意思第一次发帖发错位置了。这是对变量交换的几种方法的总结,第一种比较常用,记住第一种,其他了解就行,如果你觉得好,那就给加技术分吧。非常感谢你给的技术分哦{:soso__13165319925079696742_3:}
#region 第一种方法 中间变量交换
//int a = 6;
//int b = 9;
//int temp = a;
//a = b;
//b = temp;
//Console.WriteLine("a={0},b={1}", a, b);
//Console.ReadKey();
#endregion
#region 第二种方法
//int num1 = 5;
//int num2 = 10;
//num1 = num1 + num2;
//num2 = num1 - num2;
//num1 = num1- num2;
//Console.WriteLine("num1={0},num2={1}",num1,num2);
//Console.ReadKey();
#endregion
#region 第三种方法
//int num1 = 5;
//int num2 = 10;
//num1 = num1 * num2;
//num2 = num1 / num2;
//num1 = num1 / num2;
//Console.WriteLine("num1={0},num2={1}", num1, num2);
//Console.ReadKey();
#endregion
#region 第四种方法
//int num1 = 5;
//int num2 = 10;
//num1 = num1 | num2;
//num2 = num1 ^ num2;
//num1 = num1 ^ num2;
//Console.WriteLine("num1={0},num2={1}", num1, num2);
//Console.ReadKey();
#endregion
#region 第五种方法
//int num1 = 5;
//int num2 = 10;
//num1 = num2 + (num2 = num1) * 0;
//Console.WriteLine("num1={0},num2={1}",num1,num2);
#endregion
|
|