Jump to content

Array

- - - - -

  • Please log in to reply
No replies to this topic

#1
jellybean

jellybean

    Newbie

  • Members
  • Pip
  • 2 posts
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));

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users