String.CopyTo() method gets the string characters and places them into an array. A group of characters are copied from source string into a character array.
The following is the Copy() method −
Example
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
Output... is
String.Copy() creates a new string object with similar content.
Example
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
Output... Welcome!