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!
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP