I just learn how to create an array literal in 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" }
Now, I want to use A LITERAL ARRAY in a condition (see pseudo-code)
If 1 exists in {1,2,3,4} Then
MsgBox "Exists!"
End If
but I don’t know how, seems like you have to assign it to a variable before you can use it in the condition.
Dim MyArray() As Integer = {3, 2, 3}
If (MyArray.Contains(1)) Then
MsgBox("exists!")
Else
MsgBox("does not exist!")
End If
The above code works, but I’m just wondering is there any way to do this without assigning the array literal to variable first?
Thanks in advance!
Use
{1,2,3,4}.Contains(1)for this.