Mono Class Library: System.String Overview | Members

System.String.CopyTo Method

Copies a specified number of characters from a specified position in the current string instance to a specified position in a specified array of Unicode characters. [Edit]

public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count)

Parameters

sourceIndex
A int containing the index of the current instance from which to copy. [Edit]
destination
An array of Unicode characters. [Edit]
destinationIndex
A int containing the index of an array element in destination to copy. [Edit]
count
A int containing the number of characters in the current instance to copy to destination. [Edit]

Exceptions

TypeReason
ArgumentNullExceptiondestination is a null reference. [Edit]
ArgumentOutOfRangeException

sourceIndex, destinationIndex, or count is negative

-or-

count is greater than the length of the substring from startIndex to the end of the current instance

-or-

count is greater than the length of the subarray from destinationIndex to the end of destination

[Edit]

Remarks

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

Example

The following example demonstrates copying characters from a string to a Unicode character array.

C# Example
using System;
public class StringCopyToExample {
 public static void Main() {
 string str = "this is the new string";
 Char[] cAry = {'t','h','e',' ','o','l','d'};
 Console.WriteLine( "The initial string is '{0}'", str );
 Console.Write( "The initial character array is: '" );
 foreach( Char c in cAry)
 Console.Write( c );
 Console.WriteLine( "'" );
 str.CopyTo( 12, cAry, 4, 3 );
 Console.Write( "The character array after CopyTo is: '" );
 foreach( Char c in cAry)
 Console.Write( c );
 Console.WriteLine("'");
 }
}
   

The output is

The initial string is 'this is the new string'
The initial character array is: 'the old'
The character array after CopyTo is: 'the new'

Requirements

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