【发布时间】:2011-10-17 22:21:58
【问题描述】:
我刚刚学习了如何在 VB.NET 中创建一个数组字面量。
Dim MyArray = New Integer() { 1, 2, 3 }
' Or
Dim MyArray() As Integer = { 1, 2, 3 }
' Or
Dim MyArray() = { 1, 2, 3 }
' Or
Dim MyArray() = { 1, 2, "A", "B" }
现在,我想在条件中使用 A LITERAL ARRAY(请参阅伪代码)
If 1 exists in {1,2,3,4} Then
MsgBox "Exists!"
End If
但我不知道如何,似乎您必须先将其分配给变量,然后才能在条件中使用它。
Dim MyArray() As Integer = {3, 2, 3}
If (MyArray.Contains(1)) Then
MsgBox("exists!")
Else
MsgBox("does not exist!")
End If
上面的代码有效,但我只是想知道有没有办法在不先将数组文字分配给变量的情况下做到这一点?
提前致谢!
【问题讨论】:
标签: vb.net arrays conditional-statements literals