循环的日期时间范围vb.net

循环的日期时间范围vb.net,vb.net,datetime,loops,for-loop,next,Vb.net,Datetime,Loops,For Loop,Next,我在VB.NET应用程序中有两个日期时间值 Dim startDate作为日期时间 Dim endDate作为日期时间 现在我想在startDate和endDate之间每天循环一次,如下所示: 以整数形式表示的每一天 下一个 有人有主意了吗?C#: for(DateTime CurrentDate = StartDate; CurrentDate < EndDate; CurrentDate = CurrentDate.AddDays(1)) { } for(Date

我在VB.NET应用程序中有两个日期时间值

Dim startDate作为日期时间 Dim endDate作为日期时间

现在我想在startDate和endDate之间每天循环一次,如下所示:

以整数形式表示的每一天

下一个

有人有主意了吗?

C#

for(DateTime CurrentDate = StartDate; 
    CurrentDate < EndDate; 
    CurrentDate = CurrentDate.AddDays(1))
{
}
for(DateTime CurrentDate=StartDate;
当前日期<结束日期;
CurrentDate=CurrentDate.AddDays(1))
{
}
VB.NET

Dim CurrentDate As DateTime = StartDate
While CurrentDate < EndDate
    CurrentDate = CurrentDate.AddDays(1)
End While
Dim CurrentDate As DateTime=StartDate
当CurrentDate
Dim currentDate As Date=startDate

而currentDate Oops。。。我用C#自动回答。感谢这项工作,但我得到了一个更好的方法,对于搜索解决方案的人员,请查看TimeSpan对象。谢谢anyway@Vincent:如果您已经编辑了您的问题以添加此解决方案,那么对于搜索解决方案的人来说将是一件好事。顺便说一句,Timespan不包含日期,只包含日期之间的持续时间。因此,我不知道如何从时间跨度中获取startdate和enddate之间的日期!哇,感谢anwsers,我已经找到了其他一些最佳解决方案:如果你找到了自己的问题解决方案,那么请将其作为答案发布,并将其作为正确答案接受(你不会因此收到任何代表,所以这样做很好)。这样其他人也可以从中受益。
Dim currentDate As Date = startDate 
While currentDate <= endDate
    'do something with this date...'
    currentDate = currentDate.AddDays(1)
End While