The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Arrays with non-zero upper and lower bounds...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eric Gunnerson

Posts: 1006
Nickname: ericgu
Registered: Aug, 2003

Eric Gunnerson is a program manager on the Visual C# team
Arrays with non-zero upper and lower bounds... Posted: Mar 18, 2004 5:15 PM
Reply to this message Reply

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
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Eric Gunnerson
Latest Posts From Eric Gunnerson's C# Compendium

Advertisement
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.

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

Topic: The Calm Before the Storm...and more Watch Musings Previous Topic   Next Topic Topic: Two new additions to my blog home page...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use