C# | CharEnumerator.Reset() Method
CharEnumerator.Reset Method is used to initializes the index to a position logically before the first character of the enumerated string.
Syntax:
public void Reset ();
Below are the programs to illustrate the use of CharEnumerator.Reset() Method:
Example 1:
using System;
class GFG {
public static void Main()
{
string str = "The Sun rises in the East and sets in the West." ;
CharEnumerator chEnum = str.GetEnumerator();
while (chEnum.MoveNext())
Console.Write(chEnum.Current);
chEnum.Reset();
Console.WriteLine();
while (chEnum.MoveNext())
Console.Write(chEnum.Current);
}
}
|
Output:
The Sun rises in the East and sets in the West.
The Sun rises in the East and sets in the West.
Example 2:
using System;
class GFG {
public static void Main()
{
string str = "0 1 2 3 4 5 6 7 8 9" ;
CharEnumerator chEnum = str.GetEnumerator();
while (chEnum.MoveNext())
Console.Write(chEnum.Current);
chEnum.Reset();
Console.WriteLine();
while (chEnum.MoveNext())
Console.Write(chEnum.Current);
}
}
|
Output:
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
Reference:
Last Updated :
30 Apr, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...