Access array field with indexer - CSharp Custom Type

CSharp examples for Custom Type:Indexer

Description

Access array field with indexer

Demo Code

using System;/*from  ww  w  .ja v a  2 s  .c o m*/
class BirthsList
{
   private uint[] births = new uint[4];
   public uint this [uint index]
   {
      get
      {
         return births[index];
      }
      set
      {
         births[index] = value;
      }
   }
}
class BirthListTester
{
   public static void Main()
   {
      BirthsList bLDenmark = new BirthsList();
      uint sum;
      bLDenmark[0] = 1;
      bLDenmark[1] = 2;
      bLDenmark[2] = 4;
      bLDenmark[3] = 6;
      sum = bLDenmark[0] + bLDenmark[1] + bLDenmark[2] + bLDenmark[3];
      Console.WriteLine("Sum the four regions: {0}", sum);
   }
}

Result


Related Tutorials