Introduction:

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

Description:

In c# programming language Copy() method is a string method, the Copy() method is used to create a new instance of string object with the same value of specified string object. The copy method will return a string object that has a same value as the original string but it represents a new object reference.


C# Copy() Method Example

Following is the example of using string Copy() method to create a new string object with the same content of specified string in c# programming language.

 

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

 

As you see above example, we used a string Copy() method to create a new string object with the content of specified string object.


As you see above example, we used a ReferenceEquals method to check whether the original and copy method stringobjects 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 copy method in c#

As you see above result, the string Copy() method has returned the copy of same string object.

 

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

 

I hope it will help to you after reading.

 

0 comments


Leave a comment

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

You may also like