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.
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
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
- Shallow Copy and Deep Copy in C#
- C# | Copy Constructor
- C# | Get a read-only copy of the OrderedDictionary
- C# | Copy the Stack to an Array
- C# | Copy StringCollection at the specified index of array
- C# | How to create a shallow copy of the BitArray
- How to create a shallow copy of ArrayList in C#
- C# | Copy StringDictionary to Array at the specified index
- How to create a shallow copy of Hashtable in C#
- How to create a shallow copy of BitArray in C#
- C# | Copy the entire LinkedList<T> to Array
- C# | How to copy the entire ArrayList to a one-dimensional Array
- C# | Copy the elements of a string array to the end of the StringCollection
- C# | Copy ListDictionary to Array instance at the specified index
- How to create a shallow copy of SortedList Object in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet