VB.NET equivalent to C# var keyword

Jack picture Jack · Mar 19, 2010 · Viewed 90.7k times · Source

Is there a VB.NET equivalent to the C# var keyword?

I would like to use it to retrieve the result of a LINQ query.

Answer

Adam Robinson picture Adam Robinson · Mar 19, 2010

Option Infer must be on in order for this to function properly. If so, then omitting the type in VB.NET (Visual Basic 9) will implicitly type the variable.

This is not the same as "Option Strict Off" in previous versions of VB.NET, as the variable is strongly-typed; it's just done so implicitly (like the C# var) keyword.

Dim foo = "foo"

foo is declared as a String.