VB.NET equivalent to C# var keyword [duplicate] Ask Question

VB.NET equivalent to C# var keyword [duplicate] Ask Question

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.

ベストアンサー1

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.

おすすめ記事