Use named iterators : IEnumerator : Data Structure C# Examples


C# Examples » Data Structure » IEnumerator »

 

Use named iterators









    
using  System;  
using  System.Collections;  
  
class  MyClass  {  
    char  ch  =  '1';  
  
    public  IEnumerable  MyItr(int  end)  {  
        for(int  i=0;  i  <  end;  i++)  
            yield  return  (char)  (ch  +  i);  
    }  
}  
  
class  MainClass  {  
    public  static  void  Main()  {  
        MyClass  mc  =  new  MyClass();  
  
        foreach(char  ch  in  mc.MyItr(7))  
            Console.Write(ch  +  "  ");  
  
        Console.WriteLine("\n");  
  
    }  
}
    
   
  
   



Output

1 2 3 4 5 6 7


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» IEnumerator