views:

92

answers:

1

Can a VB.NET For loop be constructed that mimics this C# code?

TimeSpan oneDay = TimeSpan.FromDays(1.0);
for (DateTime d = startDate; d < endDate; d += oneDay) {
    // some code
}

Obviously you could do it without a For loop (i.e., with a While); I'm just curious if there's a certain syntax to construct a VB.NET For loop with a non-integer increment that I'm not aware of.

+1  A: 

No, it's not possible, the VB For loop does not support using a DateTime.

ho1
It certainly seems like you're right; but do you have a reference?
Dan Tao
Well the documentation says *Data Types. The data type of counter is usually Integer but can be any type that supports the greater than or equal to (>=), less than or equal to (<=), addition (+), and subtraction (-) operators. It can even be a user-defined type provided it supports all these operators.*. `DateTime` only has static versions of those methods.
ho1
The link I copied that from: http://msdn.microsoft.com/en-us/library/5z06z1kb%28VS.80%29.aspx
ho1
@ho: I think the issue with `DateTime` isn't that the versions are static (operator overloading is always static, I believe) but rather that `DateTime` does not define the `+` operator on another `DateTime` -- it's defined on a `TimeSpan`. That said, your comment definitely answers the question for good.
Dan Tao