Advance the enumerator to the next element of the StringCollection in CSharp
Description
The following code shows how to advance the enumerator to the next element of the StringCollection.
Example
using System;/*www. j a va 2 s .co m*/
using System.Collections.Specialized;
public class SamplesStringEnumerator {
public static void Main() {
StringCollection myCol = new StringCollection();
String[] myArr = new String[] { "A", "B", "C"};
myCol.AddRange( myArr );
StringEnumerator myEnumerator = myCol.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.WriteLine( "{0}", myEnumerator.Current );
Console.WriteLine();
myEnumerator.Reset();
if ( myEnumerator.MoveNext() )
Console.WriteLine( "The first element is {0}.", myEnumerator.Current );
}
}
The code above generates the following result.