开发者

How to get a list of week days in a month?

In this other question it shows how to 开发者_StackOverflow中文版get all days of a month. I need the same thing, but I only want to list days of week (I want to exclude weekends).

How can I get a list of days of a month excluding weekends?


Well, how about:

public static List<DateTime> GetDates(int year, int month)
{
   return Enumerable.Range(1, DateTime.DaysInMonth(year, month))
                    .Select(day => new DateTime(year, month, day))
                    .Where(dt => dt.DayOfWeek != DayOfWeek.Sunday &&
                                 dt.DayOfWeek != DayOfWeek.Saturday)
                    .ToList();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜