我正在写一个整周都要经历的循环。它看起来像这样:
DateTime TheDate = DateTime.UtcNow.AddDays(-365);
while(TheDate.Date <= DateTime.UtcNow.Date)
{
TheDate.AddDays(1);
if (TheDate.DayOfWeek == 5 || TheDate.DayOfWeek == 6)
{
continue;
}
SomeMethod(TheDate);
}
问题是TheDate
永远不会增加。为什么这样,我该如何解决?
感谢。
答案 0 :(得分:6)
AddDays
会返回DateTime
的新实例,所以:
TheDate = TheDate.AddDays(1);