C# 中 String.Copy() 和 String.CopyTo() 方法有什么区别?
String.CopyTo() 方法获取字符串字符并将它们放入数组中。将一组字符从源字符串复制到字符数组中。
以下为 Copy() 方法。-
示例
using System;
class Demo {
static void Main(String[] args) {
string str = "This is it!";
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!
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP