c#变量交换

 static void Main(string[] args)
        {
            int n1 = 10;
            int n2 = 20;

            //使用第三方变量
            int temp = n1;
            n1 = n2;
            n2 = temp;

            //不使用第三方变量
            n1 = n1 - n2;
            n2 = n1 + n2;
            n1 = n2 - n1;

            Console.WriteLine("交换后N1值为{0},N2值为{1}", n1, n2);
            Console.ReadKey();
        }

 

posted @ 2019-04-18 18:45  _Huang95  阅读(288)  评论(0编辑  收藏  举报