如何在C#中将一个字符串复制到另一个字符串
要将一个String复制到另一个String中,代码如下-
示例
using System;public class Demo {
static public void Main(){
string str1 = "Kevin";
string str2 = String.Copy(str1);
Console.WriteLine("String1 = "+str1);
Console.WriteLine("String2 = "+str2);
}
}
输出结果
这将产生以下输出-
String1 = KevinString2 = Kevin
示例
现在让我们来看另一个示例-
using System;public class Demo {
static public void Main(){
string str1 = "Maisie";
string str2 = "Ryan";
Console.WriteLine("String1 (Before copying) = "+str1);
Console.WriteLine("String2 (Before copying) = "+str2);
str2 = String.Copy(str1);
Console.WriteLine("String1 = "+str1);
Console.WriteLine("String2 (Updated) = "+str2);
}
}
输出结果
这将产生以下输出-
String1 (Before copying) = Maisie String2 (Before copying) = RyanString1 = Maisie
String2 (Updated) = Maisie
以上是 如何在C#中将一个字符串复制到另一个字符串 的全部内容, 来源链接: utcz.com/z/349000.html