System Namespace
Supports iterating over, and providing read-only access to, the individual characters in a String.
Visibility |
Name |
Value Type |
Accessibility |
public |
Current
|
Char |
[ Get ] |
|
An instance of CharEnumerator is used to support the foreach statement of the Microsoft Visual Basic and C# programming languages, and provide read-only access to the characters in a String object.
When a CharEnumerator is instantiated, it saves the current "view" of the String. Several independent instances of CharEnumerator, each with its own view, can exist simultaneously for a single instance of String. Modifications to the underlying String invalidate the associated view, causing all subsequent CharEnumerator method operations to throw an exception.
An instance of CharEnumerator maintains information specifying its current character position in a String. The state of that position is valid when it is over a character within the String, and invalid when it is before the first character or after the last character in the String. Attempting any method operation while the character position is in an invalid state throws and exception.
Initially, the current character position is before the first character in the String. That position can be incremented by one with the MoveNext method, and returned to before the first character with the Reset method. The character at the current character position can be retrieved with the Current property.
String IEnumerator IEnumerable ICollection