using System;
using System.Collections.Generic;
using System.Text;
namespace KnowledgePoint
{
class No3_VariableExchange
{
static void Main(string[] args)
{
// 空杯原理
int num01 = 10, num02 = 20;
Console.WriteLine("交换前:num01 = {0},num02 = {1}", num01, num02);
int temp = 0;
temp = num01;
num01 = num02;
num02 = temp;
Console.WriteLine("交换后:num01 = {0},num02 = {1}", num01, num02);
// 算法原理
int num01 = 10, num02 = 20;
Console.WriteLine("交换前:num01 = {0},num02 = {1}", num01, num02);
Console.WriteLine("交换后:num01 = {0},num02 = {1}",
(num01 + num02) - num01, (num01 + num02) - num02);
}
}
}
C#经典谈资——变量间值的交换
最新推荐文章于 2022-03-15 19:13:13 发布