How to find the upper bounds of a dimension in a two dimensional array?

pbizzle

New member
Joined
Mar 4, 2010
Messages
3
Programming Experience
1-3
Example: Array(Dimension1, Dimension2). Find the upperbounds of Dimension1 and find the upperbounds of Dimension2.
 
What i really want to know is how to use the method with multi-dimensional arrays. So if i were to do (given my example from the original post) Array.getupperbounds(1) would that get the upperbounds of the First Dimension of the array and would Array.getupperbounds(2) get the second dimension of the array.

Ultimately, I need to be able to figure out how many what the highest number is in each of the dimensions.

Thanks.
 
Because multidimensional arrays can be jagged, you'll need to keep track of the ubber bound for each dimension separately.
VB.NET:
Dim SomeArray(3, 4, 5) As SomeObject
Dim UbberBounds(SomeArray.Length) As Integer

For Counter As Integer = 0I To SomeArray.Length
    UpperBounds(Counter) = SomeArray.GetUpperBound(Counter)
Next Counter
 
Thanks a bunch

Your solution is so simple. Sometimes the things that seem the most complicated have simple solutions. Thanks!
 
pbizzle said:
Array.getupperbounds(1) would that get the upperbounds of the First Dimension
help said:
dimension
Type: System..::.Int32
A zero-based dimension of the Array whose upper bound needs to be determined.
So rank 0 is the first dimension. And speaking of rank, have a look through this: Array Members (System)
help said:
Length Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.
Rank Gets the zero-based rank (number of dimensions) of the Array.
JBs example should then be
VB.NET:
For dimension As Integer = 0 To someArray.Rank - 1
 
Because multidimensional arrays can be jagged
They cannot. A multidimensional array and a jagged array are inherently different things. A multidimensional array is a matrix and inherently rectangular, while a jagged array is actually a one-dimensional array of one-dimensional arrays. The syntactic difference is subtle but the semantic difference is much greater.
VB.NET:
Dim myMultiDimesionalArray As Object(,)
Dim myJaggedArray As Object()()
 
Back
Top