Demonstrate an enumerator : Enum : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » Enum »

 

Demonstrate an enumerator









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/

// Demonstrate an enumerator. 
 
using System; 
using System.Collections; 
 
public class EnumeratorDemo {  
  public static void Main() { 
    ArrayList list = new ArrayList(1); 
 
    for(int i=0; i < 10; i++) 
      list.Add(i); 
 
    // Use enumerator to access list. 
    IEnumerator etr = list.GetEnumerator(); 
    while(etr.MoveNext())  
      Console.Write(etr.Current + " "); 
 
    Console.WriteLine(); 
 
    // Re-enumerate the list. 
    etr.Reset(); 
    while(etr.MoveNext())  
      Console.Write(etr.Current + " "); 
 
    Console.WriteLine(); 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» Enum