String.Copy Method
.NET Framework 4.5
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Parameters
- str
- Type: System.String
The string to copy.
| Exception | Condition |
|---|---|
| ArgumentNullException | str is null. |
The following example displays two disimilar strings referenced by two variables, creates a copy of the first string, assigns a reference to the new string to the second variable, then displays the two strings referenced by the variables to demonstrate that the strings are now identical.
// Sample for String.Copy() using System; class Sample { public static void Main() { string str1 = "abc"; string str2 = "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' */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.