Indexer based on 0 or non-zero : Indexer : Class C# Examples


C# Examples » Class » Indexer »

 

Indexer based on 0 or non-zero









    
using  System;

class  MyClass
{
      int  value0;  
      int  value1;  
      public  int  this[int  index]  
      {
            get
            {
                  return  (0  ==  index)  ?  value0  :  value1;
            }
            set
            {
                  if  (0  ==  index)
                        value0  =  value;  
                  else
                        value1  =  value;  
            }
      }
}

class  MainClass
{
      static  void  Main()
      {
            MyClass  a  =  new  MyClass();
            Console.WriteLine("Values  --  T0:  {0},  T1:  {1}",  a[0],  a[1]);
            a[0]  =  15;
            a[1]  =  20;
            Console.WriteLine("Values  --  T0:  {0},  T1:  {1}",  a[0],  a[1]);
      }
}
    
   
  
   



Output

Values -- T0: 0, T1: 0
Values -- T0: 15, T1: 20


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Indexer