System.String.ToCharArray Method

Copies the characters in a specified substring in this instance to a Unicode character array.

Syntax

public char[] ToCharArray (int startIndex, int length)

Parameters

startIndex
The starting position of a substring in this instance.
length
The length of the substring in this instance.

Returns

A Unicode character array whose elements are the length number of characters in this instance starting from character position startIndex.

Exceptions

TypeReason
ArgumentOutOfRangeException

startIndex or length is less than zero.

-or-

startIndex plus length is greater than the length of the current instance.

Remarks

The startIndex parameter is zero-based. That is, the index of the first character in the string instance is zero.

If length is zero, the returned array is empty and has a zero length. If this instance is null or an empty string (""), the returned array is empty and has a zero length.

Requirements

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