In this article we will explain how to use string Clone() method or what is string Clone () method in c# with example.


In c# programming language Clone() method is a string method, the Clone() method is used to clone the string object and return a copy of the specified string object. The return value of clone method is not an independent copy of specified string because the clone method will simple return an existing string instance.


C# String Clone Method Example


Following is the example of using string Clone() method to clone a specified string object and return a copy of same data in c# programming language.

using System;
namespace SQLTutorialsPoint
    class Program
        static void Main(string[] args)
            string str = "Welcome to SQL Tutorials Point";
            string str1 = (string)str.Clone();
            Console.WriteLine("String:{0}", str);
            Console.WriteLine("Clone String: {0}", str1);
            Console.WriteLine("Reference Equals: {0}", Object.ReferenceEquals(str,str1));
            Console.WriteLine("\nPress Enter Key to Exit..");

As you see above example, we used a stringClone() method to clone a specified string and return an instance of specified string as result.

Here we used a ReferenceEquals method to check whether the original and cloned string objects are referring the same instance or not.

When we execute above c# program, we will get the result like as shown below.

 How to use string clone method in c#

As you see above result, the string Clone() method has cloned the given string and returned the copy of same string object.

In this article we have learned, how we can use Clone() method in c# programming language based on our requirements.


I hope it will help to you after reading.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like