StringEnumerator supports a simple iteration over a StringCollection. : StringCollection « Collections Data Structure « C# / C Sharp






StringEnumerator supports a simple iteration over a StringCollection.

 

using System;
using System.Collections.Specialized;

public class SamplesStringEnumerator  {

   public static void Main()  {
      StringCollection myCol = new StringCollection();
      String[] myArr = new String[] { "a", "o", "y"};
      myCol.AddRange( myArr );
      StringEnumerator myEnumerator = myCol.GetEnumerator();
      while ( myEnumerator.MoveNext() )
         Console.WriteLine( "{0}", myEnumerator.Current );
      myEnumerator.Reset();
      if ( myEnumerator.MoveNext() )
         Console.WriteLine( "The first element is {0}.", myEnumerator.Current );
   }

}

   
  








Related examples in the same category

1.StringCollection represents a collection of strings.
2.Adds a string to the end of the StringCollection.
3.Removes all the strings from the StringCollection.
4.Determines whether the specified string is in the StringCollection.
5.Copies the entire StringCollection values to a one-dimensional array of strings