String.Copy Method
Silverlight
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Parameters
- str
- Type: System.String
The string to copy.
| Exception | Condition |
|---|---|
| ArgumentNullException | str is null. |
The following code 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 Example { public static void Demo(System.Windows.Controls.TextBlock outputBlock) { string str1 = "abc"; string str2 = "xyz"; outputBlock.Text += String.Format("1) str1 = '{0}'", str1) + "\n"; outputBlock.Text += String.Format("2) str2 = '{0}'", str2) + "\n"; outputBlock.Text += "Copy..." + "\n"; str2 = String.Copy(str1); outputBlock.Text += String.Format("3) str1 = '{0}'", str1) + "\n"; outputBlock.Text += String.Format("4) str2 = '{0}'", str2) + "\n"; } } /* This example produces the following results: 1) str1 = 'abc' 2) str2 = 'xyz' Copy... 3) str1 = 'abc' 4) str2 = 'abc' */
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.