Учитывая два периода дат, как я могу получить день в каждом месяце вместе с месяцем, в котором он находится? - PullRequest
0 голосов
/ 04 мая 2020

Учитывая два периода дат, как я могу получить день в каждом месяце вместе с месяцем, в котором он находится? Учитывая следующие две даты, как я могу получить приведенный ниже вывод?

 public class Program
    {
        public static void Main(string[] args)
        {
            var dict = new Dictionary<DateTime,DateTime>();
            var startDate = new DateTime(2019,12,12);
            var endDate = new DateTime(2020,04,18);
            for(int i=startDate.Month,j=startDate.Year; i<=endDate.Month || j<=endDate.Year; i++){
               Console.WriteLine(startDate.Day + " days " + DateTime.DaysInMonth(startDate.Year,startDate.Month));
               startDate = new DateTime(startDate.AddMonths(1).Year,startDate.AddMonths(1).Month,DateTime.DaysInMonth(startDate.AddMonths(1).Year,startDate.AddMonths(1).Month));
             }
        }
    }
//Output required
12 days out of 31,
31 days out of 31,
29 days out of 29,
31 days out of 31,
18 days out of 30

, но он отображает бесконечный l oop из следующего:

12 days out of 31
31 days out of 31
29 days out of 29
31 days out of 31
30 days out of 30
31 days out of 31
30 days out of 30
31 days out of 31
31 days out of 31
30 days out of 30
31 days out of 31
30 days out of 30
31 days out of 31
31 days out of 31
28 days out of 28
31 days out of 31
30 days out of 30
31 days out of 31
30 days out of 30
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...