two dimension dynamic array

Last post 05-08-2008 2:48 AM by rjcox. 3 replies.

Sort Posts:

  • two dimension dynamic array

    05-07-2008, 11:17 AM
    • Loading...
    • simpson
    • Joined on 12-30-2006, 7:27 PM
    • Posts 3

    Hello.

    New to asp.net and c#

    I want to be able to populate a two dimension array with the short year YY and the long year YYYY, for this year + the next 9 years. I have been able to put the long year into an ArrayList, but I haven't been able to get my mind around how to populate a 2D array where the values increment.

    My current ArrayList:

    public static ArrayList tenYear

    {

    get

    {

    int intYear = DateTime.Now.Year;

    int stopYear = intYear + 10;

    ArrayList theArray = new ArrayList();

    int i;

    for (i = intYear; i < stopYear; i++)

    {

    theArray.Add(i);

    }

    return theArray;

    }

    }

  • Re: two dimension dynamic array

    05-07-2008, 11:27 AM

    You can also use Generics to do something like that

    List<int,int> tenYear = new List<int,int>();

     

    Cheers
    Al
    My Blog
    Follow me
    Please click on 'Mark as Answer' if this post answered your question!
  • Re: two dimension dynamic array

    05-08-2008, 2:46 AM
    Answer
    • Loading...
    • rjcox
    • Joined on 12-19-2007, 2:14 PM
    • Basingstoke, UK
    • Posts 872

    simpson:
    I want to be able to populate a two dimension array with the short year
     

    This sounds like a learning exercise, you will gain the most from solving this yourself.

    Consider: in what way does your code not do what you want it to do? Have you looked on MSDN in the C# help for array support? 

    Also you don't actually ask a question in your message.

    Richard
  • Re: two dimension dynamic array

    05-08-2008, 2:48 AM
    • Loading...
    • rjcox
    • Joined on 12-19-2007, 2:14 PM
    • Basingstoke, UK
    • Posts 872

    albertpascual:

    You can also use Generics to do something like that

    List<int,int> tenYear = new List<int,int>();

     

    Program.cs(9,4): error CS0305: Using the generic type 'System.Collections.Generic.List<T>' requires '1' type arguments

    Double check your answers before posting.

    Richard
Page 1 of 1 (4 items)