-10
ConvertingColumn[] ccsColumns = new ConvertingColumn[iConvertingColumnCount];
ArrayList[] arrConvertingColumn = new ArrayList[2];
arrConvertingColumn[0] = GetConvertingColumns(toResult, arrCorrPK, arrFirstLevelSplitColumn, arrFirstLevelCorrelationColumn, arrDataColumn);
arrConvertingColumn[1] = GetConvertingColumns(toResult, null, arrSecondLevelSplitColumn, arrSecondLevelCorrelationColumn, null);

int iCounter = 0;
for (int i = 0; i <= 3; i++)
{
   for (int j = 0; j <= arrConvertingColumn[i].Count; j++)
   {
       ccsColumns[iCounter] = (ConvertingColumn)arrConvertingColumn[i][j];
       iCounter++;
   }
}

please help me.

Matt
  • 14,906
  • 27
  • 99
  • 149
  • 2
    `arrConvertingColumn` is defined as an array with 2 elements, yet you loop over `i <= 3` – Sayse Dec 18 '14 at 08:18
  • Magic numbers are bad. What is the `3` in the outer for loop supposed to be? If you meant for it to be the length/count of items in the `ArrayList` (are you sure you can't use anything more typesafe than an `ArrayList`?), then why don't you use that respective property? --- Sorry, the ArrayList array. – Corak Dec 18 '14 at 08:23

1 Answers1

2

arrConvertingColumn is an array with size 2 since you have initialized it in this way:

ArrayList[] arrConvertingColumn = new ArrayList[2];

so you can access index 0 and 1 (arrays are zero based), but you cannot access index 2 and 3. But that are you trying if you loop until 3.

You can loop it until 1, so change:

for (int i = 0; i <= 3; i++)
{
    // ...

to

for (int i = 0; i <= 1; i++)
{
    // ...

Since the object in the ArrayList also seems to be an array use < Count instead of <= Count(again, arrays are zero based):

// ...
for (int j = 0; j < arrConvertingColumn[i].Count; j++)
{
    // ....

By the way, you should use a strongly typed ConvertingColumn[] instead of an ArrayList.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939