1, copy ();
"Syntax":
public static string Copy (String str);
Parameter--str the string to copy
Return value--a new string with the same value as Str
//Sample for string.copy ()usingSystem;classSample { Public Static voidMain () {stringSTR1 ="ABC"; stringSTR2 ="XYZ"; Console.WriteLine ("1) str1 = ' {0} '", STR1); Console.WriteLine ("2) str2 = ' {0} '", STR2); Console.WriteLine ("Copy ..."); STR2=string.copy (STR1); Console.WriteLine ("3) str1 = ' {0} '", STR1); Console.WriteLine ("4) str2 = ' {0} '", STR2); }}/*This example produces the following results:1) str1 = ' abc ' 2) str2 = ' xyz ' Copy ... 3) str1 = ' abc ' 4) str2 = ' abc '*/
2, CopyTo ();
"Syntax":
public void CopyTo (int sourceIndex, //is the starting position of the character to be copied char[] destination, //for the target character array int Destinatio NIndex, //Specifies the starting position in the destination array int count //Specifies the number of characters to copy. )
stringStrsource ="changed";Char[] Destination = {'T','h','e',' ','I','N','I','T','I','a','L',' ','a','R','R','a','y' }; Console.WriteLine (destination);//Result: The initial arrayStrsource.copyto (0, Destination,4, strsource.length); Console.WriteLine (destination);//Result: the changed arraystrsource="A Different string"; Strsource.copyto (2, Destination,3,9); Console.WriteLine (destination);//results: ThedifferentarrayConsole.readkey ();
String class-copying copy () and CopyTo ()