ylbtech-Arithmetic:Console-算法[for,if]-不用第三个变量,交换两字符串的值 |
1.A,Demo(案例) |
Console-算法[for,if]-不用第三个变量,交换两字符串的值
1.B,Solution(解决方案) |
using System; namespace ConsoleApplication1 { class Program { /// <summary> /// ylb:算法 /// 不用第三个变量,交换两字符串的值 /// </summary> /// <param name="args"></param> static void Main(string[] args) { string str1 = "abc"; string str2 = "123"; Console.WriteLine("交换前 str1={0},str2={1}", str1, str2); str1 = str1 + str2; str2 = str1.Replace(str2,""); str1 = str1.Replace(str2, ""); Console.WriteLine("交换后 str1={0},str2={1}", str1, str2); } } }
1.C,Execution Result(运行结果) |
交换前 str1=abc,str2=123 交换后 str1=123,str2=abc 请按任意键继续. . .
,如需转载请自行联系原作者