Multidimension Array in C# Windows Form

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
 
S

Steven Nagy

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)
 
J

Jon Skeet [C# MVP]

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
 
S

Steven Nagy

Yes, as Jon suggests...

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

Jon Skeet [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top