String.CopyTo() lấy ký tự chuỗi đặt vào mảng. Nhóm ký tự copy từ chuỗi nguồn vào mảng ký tự.
Ví dụ CopyTo()
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("Kết quả...");
Console.WriteLine(ch);
}
}
Kết quả
Kết quả... is
String.Copy() tạo object chuỗi mới với nội dung tương tự.
Ví dụ Copy()
using System;
class Demo {
static void Main(String[] args) {
string str1 = "Welcome!";
string str2 = "user";
str2 = String.Copy(str1);
Console.WriteLine("Kết quả...");
Console.WriteLine(str2);
}
}
Kết quả
Kết quả... Welcome!