I come from a C# background and have to now code in VB.Net (new job)
I am writing a code in VB.Net which works fine in C# (after syntax changes) but in VB.Net it gives error of Array bounds cannot appear in type specifiers.
C# Code
TimeSpan yesterday = new TimeSpan(1, 19, 0);
DateTime today = new DateTime(2012, 9, 4, 8, 48, 0);
DateTime ts = today.Add(new TimeSpan(9, 0, 0)).Subtract(yesterday);
VB.Net Code
Dim yesterday As New TimeSpan(1, 19, 0)
Dim today As New DateTime(2012, 9, 4, 8, 48, 0)
Dim ts As today.Add(New TimeSpan(9, 0, 0)).Subtract(yesterday)
It gives this error under New of 3rd line of VB code. Where am I wrong?
should be
or
When declaring a variable, you use
Asas type specifier.or
When assigning a value to the variable on the same line, you can omit the type specifier.
Because of this, I generally don’t mix up
AsandNewlike thisas I think it is somewhat confusing. I prefer