初始化并赋值给多个变量 vb.net [英] initialize and assign value to multiple variables vb.net
问题描述
可以在 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
你也可以
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?
推荐答案
我在 VS 2008 中对其进行了测试,但我认为 Dim 语句的语法自那以后没有改变.如果初始化它们,则必须为每个变量指定类型
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
或者你可以让VB推断类型并使用类型字符(这里!
为Single
):
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
通过将光标悬停在 VS 中的变量上,您将看到类型被正确推断为 Single
、Double
和 Integer
.您也可以将 F
用于单曲.请参阅:常量和文字数据类型 (Visual Basic)
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)
这篇关于初始化并赋值给多个变量 vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!