Mono Class Library: System.String Overview | Members

System.String.Copy Method

Creates a new instance of string with the same value as a specified instance of string. [Edit]

public static string Copy (string str)

Parameters

str
The string to be copied. [Edit]

Returns

A new string with the same value as str. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionstr is a null reference. [Edit]

Remarks

Documentation for this section has not yet been entered. [Edit]

Example

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'.
The copied string, strB, before strA.ToUpper, is 'string'.
The initial string after StringCopy and ToUpper, is 'STRING'.
The copied string, strB, after strA.ToUpper, is 'string'.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0