int number1 = 5;
int number2 = 10;
number2 -= number1; //number2=5
number1 += number2;
Console.WriteLine("改变后number1的值是:{0},number2的值是:{1}", number1, number2);
Console.ReadKey();
是假象,并不能实现交换
number2 = number2 - number1;
number1 = number1 + number2;带入第一个number1 = number1 + number2 - number1;就是number1 =number2;
但第一个式子的number2 = number2 - number1;并不能保证number2 = number1;
你这个情况只有在number2 - number1 = number1的时候实现, |