Indexers don't have to operate on actual arrays : Indexer : Class C# Examples


C# Examples » Class » Indexer »

 

Indexers don't have to operate on actual arrays









    
using  System;  
  
class  MySequence  {    
  
    public  int  this[int  index]  {  
        get  {  
            return  index  +  1;  
        }  
  
    }  
}    
    
class  MainClass  {    
    public  static  void  Main()  {    
        MySequence  sequence  =  new  MySequence();  
  
        for(int  i=0;  i  <  8;  i++)  
            Console.Write(sequence[i]  +  "  ");  
        Console.WriteLine();  
    }  
}
    
   
  
   



Output

1 2 3 4 5 6 7 8


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Indexer