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!