C# String Copy Method Example

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

The C# String.Copy() method is used to create a new instance of String with the same value as a specified String. It is a static method of the String class. Its return type is a string.

C# String Copy Method Example

The following example demonstrates the use of the Copy method:
using System;

public class StringDemo
{
    public static void Main(string[] args)
    {
        string s1 = "sourcecodeexamples";
        
        string s2 = string.Copy(s1);  
        
        Console.WriteLine(s1);    
        
        Console.WriteLine(s2);    

    }

}

Output:

sourcecodeexamples
sourcecodeexamples

Related C# String Examples


Comments