एक स्ट्रिंग को दूसरी स्ट्रिंग में कॉपी करने के लिए, कोड इस प्रकार है -
उदाहरण
using System;
public class Demo {
static public void Main(){
string str1 = "Kevin";
string str2 = String.Copy(str1);
Console.WriteLine("String1 = "+str1);
Console.WriteLine("String2 = "+str2);
}
} आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
String1 = Kevin String2 = Kevin
उदाहरण
आइए अब एक और उदाहरण देखें -
using System;
public class Demo {
static public void Main(){
string str1 = "Maisie";
string str2 = "Ryan";
Console.WriteLine("String1 (Before copying) = "+str1);
Console.WriteLine("String2 (Before copying) = "+str2);
str2 = String.Copy(str1);
Console.WriteLine("String1 = "+str1);
Console.WriteLine("String2 (Updated) = "+str2);
}
} आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
String1 (Before copying) = Maisie String2 (Before copying) = Ryan String1 = Maisie String2 (Updated) = Maisie