Results 1 to 3 of 3

Thread: [Resolved] - Retrieve Array Size [,]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Montréal, Québec
    Posts
    195

    Resolved [Resolved] - Retrieve Array Size [,]

    I need to get dynamically all sizes of a multidimensional array ( [,] ). The first size is get by intOldTab.Length but how do we get others size of the array?

    Thks









    Added green "resolved" checkmark - Hack
    Last edited by Hack; Dec 12th, 2005 at 10:26 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Montréal, Québec
    Posts
    195

    Re: Retrieve Array Size [,]

    I've found that the method "GetLowerBound" and "GetUpperBound" can mess with the rank of each size of the array. Can someone confirm that it's through theses method I can acces all dimensions of the array?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Montréal, Québec
    Posts
    195

    Re: Retrieve Array Size [,]

    I've found out.
    Here's the code for a 2 dimensionnal array [,] only

    int[,] intretTableau = new int[intLeTableau.GetUpperBound(0) + 1, intLeTableau.GetUpperBound(intLeTableau.Rank - 1) + 1];

    For more that 2 dimensions:
    GetUpperBound(n) retrieve the nth dimension of your array [,,,, ... ,,,,]
    the +1 is for initialization purpose because GetUpperBound return the length of the dimension -1.

    so
    GetUpperBound(0) retrieve the maximum for the first dimension
    GetUpperBound(1) retrieve the maximum for the second dimension
    GetUpperBound(2) retrieve the maximum for the third dimension
    .
    .
    .
    GetUpperBound(n) retrieve the maximum for the nth dimension

    Voilà!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width