Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.Copy Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Creates a new instance of String with the same value as a specified String.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static member Copy : 
        str:string -> string


Type: System.String

The string to copy.

Return Value

Type: System.String

A new string with the same value as str.

Exception Condition

str is null.

TheCopy 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 creates two string objects with different values. When it calls the Copy method to assign the first value to the second string, the output indicates that the strings represent different object references although their values are now equal. On the other hand, when the first string is assigned to the second string, the two strings have identical values because they represent the same object reference.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2018 Microsoft