System.CharEnumerator.MoveNext Method

Increments the internal index of the current CharEnumerator object to the next character of the enumerated string.

Syntax

public bool MoveNext ()

Returns

true if the index is successfully incremented and within the enumerated string; otherwise, false.

Remarks

The CharEnumerator class maintains an internal index to the enumerated string, and the CharEnumerator.MoveNext method increments the index by one. Call CharEnumerator.MoveNext after calling string.GetEnumerator or CharEnumerator.Reset to increment the current character position to the first character in the enumerated string. Check that the return value is true to determine that the current character position is valid.

If the index is already beyond the last character of the enumerated string, the index is not changed and false is returned.

Notice that if the enumerated string is empty (""), the state of the CharEnumerator is always invalid. This is because the internal index for the CharEnumerator is initially before the first character of the enumerated string and is therefore invalid. CharEnumerator.MoveNext logically sets the index after the last (nonexistent) character of the enumerated string which is also invalid.

Requirements

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