The Clone method in C# is employed to duplicate a string object, producing an additional copy of the existing data. The Clone method's return type is an object.
Signature
Example
public object Clone()
Parameters
It does not take any parameter.
Returns
It returns a reference.
C# String Clone method example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello ";
string s2 = (String)s1.Clone();
Console.WriteLine(s1);
Console.WriteLine(s2);
}
}
Output:
Output
Hello
Hello