A two-dimensional indexer : Two Dimensional Indexer : Class C# Examples


C# Examples » Class » Two Dimensional Indexer »

 

A two-dimensional indexer









    
using  System;  
  
class  MyArray2D  {    
    public  MyArray2D(int  r,  int  c)  {  
    }  
  
    //  This  is  the  indexer  for  MyArray2D.  
    public  int  this[int  index1,  int  index2]  {  
        //  This  is  the  get  accessor.  
        get  {  
                return  index1  +  index2;  
        }  
    }  
}    
    
class  MainClass  {    
    public  static  void  Main()  {    
        MyArray2D  myArray  =  new  MyArray2D(3,  5);  
        int  x;  
  
        for(int  i=0;  i  <  6;  i++)  {  
            x  =  myArray[i,i];  
            if(x  !=  -1)  Console.Write(x  +  "  ");  
        }  
        Console.WriteLine();  
  
    }  
}
    
   
  
   



Output

0 2 4 6 8 10


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Two Dimensional Indexer