Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.Net variable declaration : type or not to type?

Tags:

.net

vb.net

In VB.Net, the usual way to declare a string would be :

Dim helloWorld As String = "Hello, World!"

However, you can also use dynamic variables, such as :

Dim helloWorld = "Hello, World!"

Both would end up to be the same thing, but what would be the best practice?

like image 633
Dominic Goulet Avatar asked Oct 17 '13 17:10

Dominic Goulet


1 Answers

Use a Type!

Really. VB sits on top of .Net, and .Net works best when you stick with explicit types. The only exceptions are with Option Infer turned on (it is now by default) and you also declare variables similar to C#'s var, or if you're doing COM interop or something else that truly requires a dynamic type... and that it is exceedingly rare.

like image 171
Joel Coehoorn Avatar answered Oct 22 '22 12:10

Joel Coehoorn