这题与《列出本月所有星期天的日期》有点相似,稍微变动一下,即可完成。

 public IEnumerable<DateTime> AllSundaysInYear(int year)
    {
        System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
        for (int m = 1; m <= 12; m++)
        {
            int days = ci.Calendar.GetDaysInMonth(year, m);

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

 

相关文章:

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