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#
- File.Copy(String, String, Boolean) Method in C# with Examples
- File.Copy(String, String) Method in C# with Examples
- C# | Copy Constructor
- C# | Get a read-only copy of the OrderedDictionary
- C# | Copy the Stack to an Array
- C# | How to create a shallow copy of the BitArray
- How to create a shallow copy of Hashtable in C#
- C# | Copy StringDictionary to Array at the specified index
- How to create a shallow copy of ArrayList in C#
- C# | Copy StringCollection at the specified index of array
- How to create a shallow copy of BitArray in C#
- C# | Copy the entire LinkedList<T> to Array
- How to create a shallow copy of SortedList Object in C#
- C# | Copy the elements of a string array to the end of the StringCollection
- C# | How to copy the entire ArrayList to a one-dimensional Array
- C# | Copy ListDictionary to Array instance at the specified index
- C# | Copy OrderedDictionary elements to Array instance at the specified index
- C# | Copy the elements of collection over a range of elements in ArrayList
- C# | How to copy a String into another String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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