日期不会随着AddDays增加(1)

时间:2014-05-27 16:16:20

标签: c#

我正在写一个整周都要经历的循环。它看起来像这样:

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永远不会增加。为什么这样,我该如何解决?

感谢。

1 个答案:

答案 0 :(得分:6)

AddDays会返回DateTime的新实例,所以:

TheDate = TheDate.AddDays(1);