继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

列出本月所有星期天的日期

喵喵一只汪
关注TA
已关注
手记 315
粉丝 87
获赞 467

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

复制代码 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);
        }
    }复制代码

 

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP