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();
}
精彩评论