Mono Class Library: System.String Overview | MembersSystem.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]
|
- 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]
Type Reason ArgumentNullException destination 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]
Documentation for this section has not yet been entered. [Edit]
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'
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0