在控制台中,分别输入2个值,然后对其进行交换对调。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
class Bm { public void SwapData() { string value1, value2, dumpValue; Console.WriteLine("输入第一个值:"); value1 = Console.ReadLine(); Console.WriteLine("输入第二个值:"); value2 = Console.ReadLine(); dumpValue = value1; value1 = value2; value2 = dumpValue; Console.WriteLine("交换之后:"); Console.WriteLine("第一个值: " + value1); Console.WriteLine("第二个值:" + value2); Console.Read(); } }
测试,动画演示: