VB.Net variable declaration

Posted by dcp on Stack Overflow See other posts from Stack Overflow or by dcp
Published on 2010-06-10T14:32:25Z Indexed on 2010/06/10 14:32 UTC
Read the original article Hit count: 328

I notice that both of these compile without any compiler warnings or errors, even with Option Strict and Option Explicit both turned on:

    Dim x As Exception = New Exception("this is a test")
    Dim y = New Exception("this is another test")

My question is, is it more proper to use the first way (see variable x) or the second way (see variable y)? My guess is that VB doesn't need the As clause since the variable is being initialized in place, so the compiler can infer the type.

I tend to like the first way as it just "feels" right and is more consistent with other languages like C#, just wondered if there was some good reason for one way over the other. I guess it's really personal choice.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about variable-declaration