Dimension size error

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I am getting the error:
****************************************************************************
Array does not have that many dimensions.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Array does not have that
many dimensions.

Source Error:


Line 100: this.Session.Add("ReportTableDataBean",rtDataBean);
Line 101:
Line 102: lblCheckHistoryResults.Text +=
rtDataBean.dataTable.GetUpperBound(0).ToString() +
Line 103: rtDataBean.dataTable.GetUpperBound(1).ToString();
Line 104:
****************************************************************************

If I just use "rtDataBean.dataTable.GetUpperBound(0).ToString() ", it works
fine and displayes the number correctly. As soon as I added the
"rtDataBean.dataTable.GetUpperBound(1).ToString() ", I got the error.

This is a 2D array, here is the defininition from the code:

public string[][] dataTable;

How do I get the size of the 2nd Dimension (which is 5 at this point)?

Thanks,

Tom
 
tshad said:
I am getting the error:
****************************************************************************
Array does not have that many dimensions.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Array does not have that
many dimensions.

Source Error:


Line 100: this.Session.Add("ReportTableDataBean",rtDataBean);
Line 101:
Line 102: lblCheckHistoryResults.Text +=
rtDataBean.dataTable.GetUpperBound(0).ToString() +
Line 103: rtDataBean.dataTable.GetUpperBound(1).ToString();
Line 104:
****************************************************************************

If I just use "rtDataBean.dataTable.GetUpperBound(0).ToString() ", it works
fine and displayes the number correctly. As soon as I added the
"rtDataBean.dataTable.GetUpperBound(1).ToString() ", I got the error.

This is a 2D array, here is the defininition from the code:

public string[][] dataTable;

How do I get the size of the 2nd Dimension (which is 5 at this point)?

You don't actually have a multi-dimensional array there - you have an
array of arrays of strings.

Use dataTable.Length to find out how many string arrays you actually
have, then dataTable.Length to find out how large the array with
index i is.

If you actually want a rectangular array, use

public string[,] dataTable;
 
Jon Skeet said:
tshad said:
I am getting the error:
****************************************************************************
Array does not have that many dimensions.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Array does not have
that
many dimensions.

Source Error:


Line 100: this.Session.Add("ReportTableDataBean",rtDataBean);
Line 101:
Line 102: lblCheckHistoryResults.Text +=
rtDataBean.dataTable.GetUpperBound(0).ToString() +
Line 103: rtDataBean.dataTable.GetUpperBound(1).ToString();
Line 104:
****************************************************************************

If I just use "rtDataBean.dataTable.GetUpperBound(0).ToString() ", it
works
fine and displayes the number correctly. As soon as I added the
"rtDataBean.dataTable.GetUpperBound(1).ToString() ", I got the error.

This is a 2D array, here is the defininition from the code:

public string[][] dataTable;

How do I get the size of the 2nd Dimension (which is 5 at this point)?

You don't actually have a multi-dimensional array there - you have an
array of arrays of strings.

Use dataTable.Length to find out how many string arrays you actually
have, then dataTable.Length to find out how large the array with
index i is.

If you actually want a rectangular array, use

public string[,] dataTable;


That was what I was looking for.

Thanks,

Tom
 
Back
Top