C#中的String.Copy()和String.CopyTo()方法有什么区别?
String.CopyTo()方法获取字符串字符并将其放入数组中。一组字符从源字符串复制到字符数组中。
以下是Copy()方法-
示例
using System;
class Demo {
static void Main(String[] args) {
string str = "就是这个!";
char[] ch = new char[5];
str.CopyTo(2, ch, 0, 2);
Console.WriteLine("Output...");
Console.WriteLine(ch);
}
}输出结果
Output... is
String.Copy()创建一个内容相似的新字符串对象。
示例
using System;
class Demo {
static void Main(String[] args) {
string str1 = "Welcome!";
string str2 = "user";
str2 = String.Copy(str1);
Console.WriteLine("Output...");
Console.WriteLine(str2);
}
}输出结果
Output... Welcome!
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短