好吧,您需要以一种或另一种方式遍历它们。我更喜欢定义这样的方法:
public IEnumerable<DateTime> EachDay(DateTime from, DateTime thru){ for(var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1)) yield return day;}然后,您可以像这样使用它:
foreach (DateTime day in EachDay(StartDate, EndDate)) // print it or whatever
通过这种方式,您可以每隔一天,每隔三天,仅工作日等等进行打。例如,要每隔三天从“开始”日期开始返回,可以直接
AddDays(3)在循环中调用而不是
AddDays(1)。



