Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
ConvertingColumn[] ccsColumns = new ConvertingColumn[10];
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..thanks in advance
Posted
Updated 17-Dec-14 19:52pm
v4
Comments
Praveen Kumar Upadhyay 18-Dec-14 1:27am    
How many rows "arrConvertingColumn" object has? and what is the length you have defined to ccsColumns object. Problem is with your ccsColumns object length or no of row(arrConvertingColumn object) is less than what your are defining in the first for loop
Member 11319374 18-Dec-14 1:34am    
array list "arrConvertingColumn" has 6columns
Praveen Kumar Upadhyay 18-Dec-14 1:35am    
I have asked, how many rows it has and what is the length defined for arrConvertingColumn object
Member 11319374 18-Dec-14 1:38am    
ConvertingColumn[] ccsColumns = new ConvertingColumn[10];
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++;
}
}

You should probably not use <= in your for loops as c# uses index that starts at 0.

Consider the following.
C#
       Index: 0  1  2  3
int[] arr = { 4, 6, 7, 5 };

In the case above, the variable arr contains four elements -> count = 4, but the last index is 3.
If you try to do
C#
int x = arr[arr.Length];

you will get an 'Index was out of range' error.

Try this:
C#
// [UPDATE] Use the size of arrConvertingColumn instead of a fixed number.
for (int i = 0, iCounter=0; i < arrConvertingColumn.Count; i++, iCounter++)
{
    for (int j = 0; j < arrConvertingColumn[i].Count; j++)
    {
        ccsColumns[iCounter] = (ConvertingColumn)arrConvertingColumn[i][j];
    }
}


That said, you don't show the size of ccsColumns, so you still might have a problem with your iCounter variable.
 
Share this answer
 
v3
Comments
Member 11319374 18-Dec-14 2:15am    
still its throwing exception
George Jonsson 18-Dec-14 2:36am    
Well, have you tried to step through the code in the debugger and checked your counters?
Check your code now. Object arrConvertingColumn has only 2 length means it can hold index 0 and 1, but in your code you are iterating the loop by saying that i<=3 which is wrong and that is why you are getting IndexBounds exception.
 
Share this answer
 
Comments
Praveen Kumar Upadhyay 18-Dec-14 6:40am    
Just wanted to know, who is this who has started devoting all my solutions and questions

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900