|
-
Dec 7th, 2005, 10:48 AM
#1
Thread Starter
Addicted Member
[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.
-
Dec 7th, 2005, 11:56 AM
#2
Thread Starter
Addicted Member
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?
-
Dec 7th, 2005, 06:03 PM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|