This blog is no longer updated please visit http://www.createdbyx.com/ instead.

Friday, April 23, 2004

Interesting VB.NET varible decloration quark...

I came across this kinda stupid quark about VB.NET and varible declorations after doing some code conversions from c# to vb.net.

ConvertCSharp2VB

If you try to declare 2 varibles on the same line and set there initial value like so you get the fallowing design time error...
Explicit initialization is not permitted with multiple variables declared with a single type specifier.

Dim a, b As Integer = 0

Strangly if you declare the varibles like so ...

Dim a As Integer, b As Integer = 0

... You no longer get the error?

I could understand this error if variants were still apart of vb.net. For example ...

Dim a, b As Integer = 0

... Would result in 'a' being a variant and 'b' being an integer. But there are no variants in vb.net. I'm guessing it's a feature the MS team has not discovered or have got around to implementing yet. BTW, I am using vs.net 2002 so this varible decloration quark may have been fixed in laters version of vs.net.