Copies a specified number of characters from a specified location in this string to a specified location in an array.
[Visual Basic] Public Sub CopyTo( _ ByVal sourceIndex As Integer, _ ByVal destination() As Char, _ ByVal destinationIndex As Integer, _ ByVal count As Integer _ ) [C#] public void CopyTo( int sourceIndex, char[] destination, int destinationIndex, int count ); [C++] public: void CopyTo( int sourceIndex, __wchar_t* destination[], int destinationIndex, int count ); [JScript] public function CopyTo( sourceIndex : int, destination : Char[], destinationIndex : int, count : int );
Exception Type | Condition |
---|---|
ArgumentNullException | If the destination is null. |
ArgumentOutOfRangeException | If soureIndex is not a valid index in this string. |
ArgumentOutOfRangeException | If count and soureIndex is not a valid index in this string. |
ArgumentOutOfRangeException | If destinationIndex is not a valid index in the array. |
ArgumentOutOfRangeException | If count and destinationIndex is not a valid index in the array. |
IndexOutOfRangeException | If the destination is not within the array. |
The CopyTo method determines the length of the string to be copied (sourceIndex plus the count), determines where to start coping the string (sourceIndex) from a specified location in this string, and copies the selected string to a specified location in an array (destinationIndex).
Only count characters are copied.
String Class | String Members | System Namespace | Char | Int32