两个值交换,不使用第三个中间变量做缓存。实现方法
方法一
int n1 = 70;
int n2 = 40;
n1 = n1 + n2; //n1=110
n2 = n1 - n2; //n2=70
n1 = n1 - n2; //n1=40
Console.WriteLine($"第一个值是{n1},第二个值是{n2}");
方法二
int n1 = 50;
int n2 = 30;
n1 = n1 - n2; //n1=20
n2 = n1 + n2; //n2=50
n1 = n2 - n1; //n1=30