Creates a new instance of string with the same value as a specified instance of string.
- str
- The string to be copied.
A new string with the same value as str.
Type Reason ArgumentNullException str is a null reference.
The following example demonstrates copying strings.
C# Example
using System;
public class StringCopyExample {
public static void Main() {
string strA = "string";
Console.WriteLine( "The initial string, strA, is '{0}'.", strA );
string strB = String.Copy( strA );
strA = strA.ToUpper();
Console.WriteLine( "The copied string, strB, before strA.ToUpper, is '{0}'.", strB );
Console.WriteLine( "The initial string after StringCopy and ToUpper, is '{0}'.", strA );
Console.WriteLine( "The copied string, strB, after strA.ToUpper, is '{0}'.", strB );
}
}
The output is
The initial string, strA, is 'string'.