C# String.Copy() strategy: Here, we will find out about the Copy() technique for String class with example.
C# String.Copy() Method
String.Copy() strategy is utilized to duplicate a string to new string item, it restores another example of String with similar value as a given string.
Syntax:
public static string Copy (string str);
Parameter: string – whose value to be duplicated
Return value: string – restores a duplicate of the given solid.
Example:
Input:
string str1 = "JustTechReview";
creating new string using String.Copy() method:
string str2 = String.Copy(str1);
Output:
str1: JustTechReview
str2: JustTechReview
C# Example to duplicate a string utilizing String.Copy() strategy:
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
string str1 = "JustTechReview";
//creating new string using String.Copy() method
string str2 = String.Copy(str1);
//printing strings
Console.WriteLine("str1: " + str1);
Console.WriteLine("str2: " + str2);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output:
str1: JustTechReview
str2: JustTechReview