This post originated from an RSS feed registered with .NET Buzz
by Eric Gunnerson.
Original Post: Arrays with non-zero upper and lower bounds...
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
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.