本作业题是列出本月所有星期天的日期。

 public IEnumerable<DateTime> AllSundaysInMonth(int year, int month)
    {
       System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
        
        int days = ci.Calendar.GetDaysInMonth(year, month);

        for (int i = 1; i <= days; i++)
        {
          if (new DateTime(year, month, i).DayOfWeek == DayOfWeek.Sunday)            
            yield return new DateTime(year, month, i);
        }
    }

 

相关文章:

  • 2021-12-02
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2021-09-27
  • 2021-10-07
相关资源
相似解决方案