列出本月偶数的日期

作业问题与要求是列出本月偶数的日期。如果会做 《显示本月每一天日期》,此题也许不是问题了。

 public IEnumerable<DateTime> AllEvenDatesInMonth(int year, int month)
    {
        int days = DateTime.DaysInMonth(year, month);

        for (int i = 1; i <= days; i++)
        {
           if (i % 2 == 0)
            yield return new DateTime(year, month, i);
        }
    }

 

posted @ 2012-06-07 22:41  Insus.NET  阅读(615)  评论(0编辑  收藏  举报