override virtual indexer - CSharp Custom Type

CSharp examples for Custom Type:virtual

Description

override virtual indexer

Demo Code

using System;/*  w ww .  j  a v  a 2  s  .c o  m*/
class ProductionList
{
   private uint[] production = new uint[4];
   public virtual uint this [uint index]
   {
      get
      {
         return production[index];
      }
      set
      {
         production[index] = value;
      }
   }
}
class ProductionVersionAdjust : ProductionList
{
   public override uint this [uint index]
   {
      get
      {
         if(index < 2)
            return base[index] + 50;
         else
            return base[index] - 30;
      }
      set
      {
            base[index] = value;
      }
   }
   public uint TotalVersionalAdjusted
   {
         get
         {
            uint tempTotal = 0;
            for(uint i = 0; i < 4; i++)
            {
               tempTotal += this[i];
            }
            return tempTotal;
         }
   }
}
class Tester
{
      public static void Main()
      {
         ProductionVersionAdjust prodAdjust = new ProductionVersionAdjust();
         prodAdjust[0] = 100;
         prodAdjust[1] = 300;
         prodAdjust[2] = 200;
         prodAdjust[3] = 500;
         Console.WriteLine("Production in first quarter season adjusted: " + prodAdjust[0]);
         Console.WriteLine("Total production seasonally adjusted: " + prodAdjust.TotalVersionalAdjusted);
      }
}

Result


Related Tutorials