using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;//引用命名空间
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//C#交换两个数的值
//方法一,利用第三个数
int a = 10;
int b = 20;
Console.WriteLine("交换前a={0},b={1}", a, b);
int temp = a;
a = b;
b = temp;
Console.WriteLine("交换后a={0},b={1}", a, b);
Console.ReadKey();
//方法二,通过加减实现
int c = 60;
int d = 40;
Console.WriteLine("交换前a={0},b={1}", c, d);
c = c + d;
d = c - d;
c = c - d;
Console.WriteLine("交换后a={0},b={1}", c, d);
Console.ReadKey();
}
}
}
C#篇(2)——C#交换两个数的值
最新推荐文章于 2024-06-25 20:09:51 发布