System.CharEnumerator Class

public sealed class CharEnumerator : ICloneable, IEnumerator

Base Types

Object
  CharEnumerator

This type implements IEnumerator and ICloneable.

Assembly

mscorlib

Library

BCL

Summary

Supports iteration over and provides read-only access to the individual characters in a String.

Description

[Note: CharEnumerator is used to support the foreach statement of the C# programming language.

Several independent instances of CharEnumerator across one or more threads can have access to a single instance of String.

For more information regarding the use of an enumerator, see IEnumerator.

]

See Also

System Namespace

Members

CharEnumerator Methods

CharEnumerator.Clone Method
CharEnumerator.MoveNext Method
CharEnumerator.Reset Method

CharEnumerator Properties

CharEnumerator.Current Property
CharEnumerator.System.Collections.IEnumerator.Current Property


CharEnumerator.Clone Method

public object Clone();

Summary

Creates a copy of the current instance.

Return Value

A Object with the same state as the current instance.

Description

The return value is a Object containing a copy of the state of the current instance when this method is invoked. This Object must be cast explicitly to a CharEnumerator to be made usable as one.

[Note: This method is useful for saving the state of a CharEnumerator object while iterating through the characters of a String .

This method is implemented to support the ICloneable interface.

]

See Also

System.CharEnumerator Class, System Namespace

CharEnumerator.MoveNext Method

public bool MoveNext();

Summary

Advances the current instance to the next element of the String if and only if the current instance is not already placed beyond the final element of the String.

Return Value

true if the enumerator was successfully advanced to the next element; otherwise, false .

Description

If the enumerator is positioned after the final element of the String when this method is called, the current instance remains in its current position and false is returned.

See Also

System.CharEnumerator Class, System Namespace

CharEnumerator.Reset Method

public void Reset();

Summary

Repositions the current instance to its initial position, immediately before the first character in the String.

See Also

System.CharEnumerator Class, System Namespace

CharEnumerator.Current Property

public char Current { get; }

Summary

Gets the element in the String over which the current instance is positioned.

Property Value

The Char in the String over which the current instance is positioned.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe current instance is positioned before the first element or after the last element of the String.

See Also

System.CharEnumerator Class, System Namespace

CharEnumerator.System.Collections.IEnumerator.Current Property

object IEnumerator.Current { get; }

Summary

Implemented to support the IEnumerator interface. [Note: For more information, see System.Collections.IEnumerator.Current.]

See Also

System.CharEnumerator Class, System Namespace