Arrays with non-zero upper and lower bounds...

In the comments to my post on zero and one based arrays, several people mentioned that they wanted to be able to have collections that ran from 4 to 10, or from 1900 to 2004 for years. Consider the following:

 public class YearClass
{
   const int StartDate = 1900;
   const int EndDate = 2050;
   int[] arr = new int[EndDate - StartDate + 1];

   public int this[int num]
   {
      get { return arr[ num - StartDate]; }
      set { arr[num - StartDate] = value; }
   }
}

public class Test
{
    public static void Main()
    {
        YearClass yc = new YearClass();
        yc[1950] = 5;
     }
}

 

I think that gives you the user model that you want.