Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

initialize and assign value to multiple variables vb.net

there is the option to do this in vb.net

Dim a, b, c As Single, x, y As Double, i As Integer

also you can do

Dim myString = String.empty

Is there a way to initialize and assign multiple variables like the first example but using the assignment as the second one?

like image 867
edgarmtze Avatar asked Sep 11 '25 23:09

edgarmtze


1 Answers

I tested it in VS 2008, but I don't think that the Syntax of the Dim statement changed since. You will have to specify the type for each variable, if you initialize them

Dim a As Single = 1, b As Single = 2, x As Double = 5.5, y As Double = 7.5

Or you can let VB infer the type and use type characters (here ! for Single):

Dim a = 1!, b = 2!, c = 3!, x = 5.5, y = 7.5, i = 100

By hovering with the cursor over the variables in VS you will see that the types are inferred correctly as Single, Double and Integer. You could also use F for single. See: Constant and Literal Data Types (Visual Basic)

like image 93
Olivier Jacot-Descombes Avatar answered Sep 13 '25 14:09

Olivier Jacot-Descombes