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 (Int32, Char[], Int32, Int32)


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)

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


Type: System.Int32

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

Type: System.Char[]

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

Type: System.Int32

The index in destination at which the copy operation begins.

Type: System.Int32

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

Exception Condition

destination is null.


sourceIndex, destinationIndex, or count is negative


sourceIndex does not identify a position in the current instance.


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


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


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

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.

public enum EmployeeStatus

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft