0

My problem is that the array does not seem to return the correct value, the same value is returned for each data row, but when I display using Response.Write in foreach in Calculation, the correct values are returned. The array values has to be used in a calculation

I've got an array function:

public int[] NumberOfDays(DateTime startDate, DateTime endDate)
    {
        TimeSpan daysCount = endDate - startDate;
        DateTime currDate;
        currDate = DateTime.MinValue + daysCount;
        int monthCount = 0;

        monthCount = (((currDate.Year - 1) * 12) + currDate.Month) - 1;
        int[] result = new int[monthCount];
        int subtractAmount = 0;

        for (int i = 0; i < monthCount; i++)
        {
            DateTime parsingDate = startDate.AddMonths(i);

            if (parsingDate.Month == 12 || parsingDate.Month == 1)
            {
                subtractAmount += 14;
            }

            result[i] = subtractAmount;
        }

        return result;
    }

used in here:

public int Calculation(DateTime start, DateTime end)
    {
int[] result;
            result = NumberOfDays(start, end);
            foreach (int res in result)
            {
                totalHolidays = (result[result.Length - 1]);
                if (res == 0)
                {
                    t1 = t1;
                }
                else
                {
                    t1 = res;
                }
                totalHolidays = (result[result.Length - 1]);
            }
         return t1;
}

Calculator is used here:

foreach (DateTime valuationDate in GetDates(start, end, validDay))
        {
 dt.Rows.Add(valuationDate.ToShortDateString(), 
                Calculation(start, end));
}
2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by jellybeannn
0

>My problem is that the array does not seem to return the correct value

Variable t1 is not declared at local scope.

0

I just didn't put the whole calculation in the post, but t1 is declared,

double t1;
        if (validation > end)
        {
            System.TimeSpan sp_last =
                end.Subtract(start);
            t1 = sp_last.TotalDays;
        }
        else
        {
            System.TimeSpan sp_start =
                validation.Subtract(start);
            t1 = sp_start.TotalDays;
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.