The C# CopyTo function is employed to duplicate a designated quantity of characters from a specific location within the string. It replicates the characters from this string into a char array.
Signature
Example
public void CopyTo(int index, char[] ch, int start, int end)
Parameter
index: An integer type parameter representing the position within a string.
ch: it is a char type array.
start: it is start index of char type array.
end: it is end index of char type array.
C# String CopyTo Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#, How Are You?";
char[] ch = new char[15];
s1.CopyTo(10,ch,0,12);
Console.WriteLine(ch);
}
}
Output:
Output
How Are You?