c#变量交换

时间:2019-04-18 19:04:40   收藏:0   阅读:101
 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();
        }

 

原文:https://www.cnblogs.com/huangxuQaQ/p/10731559.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!