A new string with the same value as str.
Type Reason ArgumentNullException str is a null reference.
The string.Copy(string) method returns a string object that has the same value as the original string but represents a different object reference. It differs from an assignment operation, which assigns an existing string reference to an additional object variable. The example illustrates the difference.
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'.