C# | Copy() Method Last Updated : 21 Jun, 2019 Comments Improve Suggest changes Like Article Like Report 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 operation, which assigns an existing string reference to an additional object variable. Syntax: public static string Copy(string str) Explanation : This method accepts single parameter str which is the original string to be copied. And it returns the string value, which is the new string with the same value as str. The type of Copy() method is System.String. Example Program to illustrate the Copy() Method csharp // C# program to demonstrate the // use of Copy() method using System; class Program { static void cpymethod() { string str1 = "GeeksforGeeks"; string str2 = "GFG"; Console.WriteLine("Original Strings are str1 = " + "'{0}' and str2='{1}'", str1, str2); Console.WriteLine(""); Console.WriteLine("After Copy method"); Console.WriteLine(""); // using the Copy method // to copy the value of str1 // into str2 str2 = String.Copy(str1); Console.WriteLine("Strings are str1 = " +"'{0}' and str2='{1}'", str1, str2); // check the objects reference equal or not Console.WriteLine("ReferenceEquals: {0}", Object.ReferenceEquals(str1, str2)); // check the objects are equal or not Console.WriteLine("Equals: {0}", Object.Equals(str1, str2)); Console.WriteLine(""); Console.WriteLine("After Assignment"); Console.WriteLine(""); // to str1 object reference assign to str2 str2 = str1; Console.WriteLine("Strings are str1 = '{0}' " +"and str2 = '{1}'", str1, str2); // check the objects reference equal or not Console.WriteLine("ReferenceEquals: {0}", Object.ReferenceEquals(str1, str2)); // check the objects are equal or not Console.WriteLine("Equals: {0}", Object.Equals(str1, str2)); } // Main Method public static void Main() { // calling method cpymethod(); } } Output: Original Strings are str1 = 'GeeksforGeeks' and str2='GFG' After Copy method Strings are str1 = 'GeeksforGeeks' and str2='GeeksforGeeks' ReferenceEquals: False Equals: True After Assignment Strings are str1 = 'GeeksforGeeks' and str2 = 'GeeksforGeeks' ReferenceEquals: True Equals: True Reference : https://msdn.microsoft.com/en-us/library/system.string.copy Comment More infoAdvertise with us Next Article C# | Copy() Method M Mithun Kumar Follow Improve Article Tags : Misc C# CSharp-method Practice Tags : Misc Similar Reads C# String CopyTo() Method 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 char 2 min read C# | Array.ConstrainedCopy() Method This method is used to copy a range of elements from an Array starting at the specified source index and pastes them to another Array starting at the specified destination index. Guarantees that all changes are undone if the copy does not succeed completely. Syntax: public static void ConstrainedCop 9 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 CopyOnWriteArrayList clone() method in Java The clone() method of CopyOnWriteArrayList returns a shallow copy of the list. The shallow copy contains exactly the same elements at the same index. Syntax: public Object clone() Parameters: The function does not accept any parameters. Return Value: The function returns a clone of the list. Below p 2 min read wmemmove() function in c++ The wmemmove() function is defined in cwchar.h header file. The wmemmove() function copies a specified number of wide characters from source to the destination.Syntax: wchar_t* wmemmove(wchar_t* dest, const wchar_t* src, size_t n); Parameters: This method accepts the following parameters: dest: spec 1 min read Like