C# String Clone Method Example

In this source code example, we will demonstrate the usage of String.Clone() method in C# with an example.

The C# String.Clone() method is used to clone a string object. It returns another copy of the same data. The return type of the Clone() method is an object.

C# String Clone Method Example

using System;

public class StringDemo
    public static void Main(string[] args)
         string s1 = "Source Code Example";    
         Console.WriteLine("Original string object : " + s1);  
         // Returns a reference to this instance of String.
         string s2 = (String)s1.Clone(); 
         Console.WriteLine("Cloned String object : " + s2);    



Original string object : Source Code Example
Cloned String object : Source Code Example

Related C# String Examples