Multidimension Array in C# Windows Form

  • Thread starter Thread starter Jason Huang
  • Start date Start date
J

Jason Huang

Hi,

I have a 2 dimension string array MyArray, how do I know the Count of the
Rows and Columns in the MyArray?
Thanks for help.


Jason
 
is it a staggered array or a rectangular array?
By this, I mean, have you declared it as:

string[][] MyArray (staggered)
or
string[,] MyArray (rectangular)
 
Jason said:
Thanks Steven,
I declare it as string[ , ] GoodString;

In that case use GoodString.GetUpperBound(0) to get the upper bound for
the first dimension, and GoodString.GetUpperBound(1) to get the upper
bound for the second dimension.

Jon
 
Yes, as Jon suggests...

string[ , ] GoodString;
....
int count = GoodString.GetUpperBound(0) * GoodString.GetUpperBound(1);
 
Steven Nagy said:
Yes, as Jon suggests...

string[ , ] GoodString;
...
int count = GoodString.GetUpperBound(0) * GoodString.GetUpperBound(1);

To get the total size is easier than that - just use GoodString.Length.
 
Back
Top