C# String CopyTo() Method Last Updated : 18 Mar, 2025 Comments Improve Suggest changes Like Article Like Report In C#, the CopyTo() is a method of String Class. It is used to copy a specified number of characters from a specified position in the string and it copies the characters of this string into an array of Unicode characters.Example 1: Using the CopyTo() method to copy characters from a string to a character array. C# // C# program to illustrate the // String.CopyTo() Method // Method using System; class Geeks { public static void Main() { // Creating a string string s = "GeeksForGeeks"; // Destination char array char[] dest = new char[3]; //Copying 3 characters from the 5th index //of the string to the destination char array. s.CopyTo(5, dest, 0, 3); // Displaying the copied string Console.WriteLine($"The Copied String is: {new string(dest)}"); } } OutputThe Copied String is: For Syntax of String CopyTo() Methodpublic void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)Parameters:sourceIndex: Index of String to be copied. Its type is System.Int32 .destination: It is the array of Unicode characters to which characters will be copied. Its type is System.Char[].destinationIndex: It is the the starting index of the array from where the copy operation begins. Its type is System.Int32.count: It is the number of characters which will copy to the destination. Its type is System.Int32.Exceptions:ArgumentNullException: If the destination array is null then it will throw this Exception.ArgumentOutOfRangeException: There are different cases when an exception occursIf sourceIndex, destinationIndex, or count is negative.If sourceIndex does not identify a position in the current instance.If destinationIndex does not identify a valid index in the destination array.If the count is greater than the length of the substring from startIndex to the end of this instanceIf the count is greater than the length of the subarray from destinationIndex to the end of the destination array.Example 2: Using the CopyTo() method to modify an existing character array. C# // C# program to illustrate the // ToCopy() string method using System; class Geeks { public static void Main() { string s = "GeeksForGeeks"; char[] dest = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' }; // str index 8 to 8 + 5 has // to copy into Copystring // 5 is no of character // 6 is start index of Copystring s.CopyTo(8, dest, 6, 5); // Displaying the result Console.Write("String Copied in dest is: "); Console.WriteLine(dest); } } OutputString Copied in dest is: Hello Geeks Comment More infoAdvertise with us Next Article C# String CopyTo() Method M Mithun Kumar Follow Improve Article Tags : Misc C# CSharp-method CSharp-string Practice Tags : Misc Similar Reads C# String Clone() Method In C#, the Clone() method is a String method. It is used to clone the string object, which returns another copy of that data. In other words, it returns a reference to this instance of String. The return value will be only another view of the same data. The Clone() method is called directly on the c 3 min read StringBuilder.CopyTo Method in C# This method is used to copy the characters from a specified segment of this instance to a specified segment of a destination Char array. Syntax: public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count); Parameters: sourceIndex: It is the starting position in this ins 2 min read Stack.CopyTo() Method in C# This method(comes under System.Collections namespace) is used to copy the Stack to an existing 1-D Array which starts from the specified array index. The elements are copied onto the array in last-in-first-out (LIFO) order, similar to the order of the elements returned by a succession of calls to Po 2 min read C# | Copy() Method In C#, Copy() is a string method. It is used to create a new instance of String with the same value for a specified String. The Copy() method returns a String object, which is the same as the original string but represents a different object reference. To check its reference, use assignment operatio 2 min read C# | CharEnumerator.ToString() Method CharEnumerator.ToString() Method is used to get a string that represents the current object. It is inherited from the Object Class. Syntax: public virtual string ToString(); Return Value: This method returns a string which represents the current CharEnumerator object. Below are the programs to illus 2 min read Queue.CopyTo() Method in C# This method is used to copy the Queue elements to an existing one-dimensional Array, starting at the specified array index. The elements are copied to the Array in the same order in which the enumerator iterates through the Queue and this method is an O(n) operation, where n is Count. This method co 4 min read CopyOnWriteArrayList toString() method in Java The toString() method of CopyOnWriteArrayList returns the string representation of the list. Syntax: public String toString() Parameters: The function does not accepts any parameter. Return Value: The function returns the string representation of the list. Below programs illustrate the above functio 1 min read File.Copy(String, String) Method in C# with Examples File.Copy(String, String) is an inbuilt File class method that is used to copy the content of the existing source file content to another destination file which is created by this function. Syntax:  public static void Copy (string sourceFileName, string destFileName); Parameter: This function acce 3 min read std::string::assign() in C++ The member function assign() is used for the assignments, it assigns a new value to the string, replacing its current contents. Syntax 1: Assign the value of string str. string& string::assign (const string& str) str : is the string to be assigned. Returns : *this CPP // CPP code for assign 5 min read Practice questions on Strings String is an important topic from GATE exam point of view. We will discuss key points on strings as well different types of questions based on that. There are two ways to store strings as character array (char p[20]) or a pointer pointing to a string (char* s = âstringâ), both of which can be access 4 min read Like