Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

String.CopyTo Method

Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

member CopyTo : 
        sourceIndex:int * 
        destination:char[] * 
        destinationIndex:int * 
        count:int -> unit

Parameters

sourceIndex
Type: System.Int32

The index of the first character in this instance to copy.

destination
Type: System.Char[]

An array of Unicode characters to which characters in this instance are copied.

destinationIndex
Type: System.Int32

The index in destination at which the copy operation begins.

count
Type: System.Int32

The number of characters in this instance to copy to destination.

ExceptionCondition
ArgumentNullException

destination is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

sourceIndex, destinationIndex, or count is negative

-or-

sourceIndex does not identify a position in the current instance.

-or-

destinationIndex does not identify a valid index in the destination array.

-or-

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

-or-

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

This method copies count characters from the sourceIndex position of this instance to the destinationIndex position of destination character array. This method does not resize the destination character array; it must have a sufficient number of elements to accommodate the copied characters or the method throws an ArgumentOutOfRangeException.

sourceIndex and destinationIndex are zero-based.

The following example demonstrates the CopyTo method.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft