Index was out of range. Must be non-negative and less than the size of the collection

Jul 20 2007 10:35 AM
"Index was out of range. Must be non-negative and less than the size of the collection" I am getting the error on the line marked with an (*): public List PersonsForYear(int year) { List lPerson = new List(); //Variable to assign array from list from specifed month int[] iPMonthly = new int[3]; //Variable to hold Year Totals for each array int[] iYearTotal = new int[3]; List lMonth = new List(); lMonth = MonthList(); for (int i = 0; i < 12; i++) { //Fill the array iPMonthly = PersonMonthlyRep(Convert.ToDateTime("01 " + lMonth[i] + " " + year)); //Assign the array to specified list ***lPerson[i] = iPMonthly; //Assigns the yearly total iYearTotal[0] += iPMonthly[0]; iYearTotal[1] += iPMonthly[1]; iYearTotal[2] += iPMonthly[2]; } //Assign the yearly total array to the list lPerson[12] = iYearTotal; return lPerson; } My query: select @enddate = dbo.ufn_GetLastDayOfMonth(@begindate) select sum(cnl.conclusion_personalive) as 'Alive', sum(cnl.conclusion_persondeceased) as 'Deceased', sum(cnl.conclusion_personmissing) as 'Missing' from tbl_conclusion cnl (nolock), tbl_incident inc (nolock) where cnl.conclusion_incidentid = inc.incident_id and inc.incident_datetime between @begindate and @enddate Overview: PersonMonthlyRep(DateTime) method returns the above query in an int[3] array, which is called 12 times for each month of the year. I then get the overall yearly total at the end. I'm assuming its something to do with the List of int arrays that i created but i can't seem to figure out what i'm doing wrong. Thanx

Answers (1)