'IN' command?

DavyEFC

Well-known member
Joined
Dec 17, 2010
Messages
51
Programming Experience
5-10
My train of thought has gone dead! I'm looking for an equivalent 'IN' command, like:
VB.NET:
S=2
if S isIn(1,2,3,4,5) then = true

to replace
VB.NET:
if S=1 then true elseif S=2 then true...

I know i could use case statement to achieve it but this is a one liner so wondering if there is such a function?

I told you my head was cabbaged! :rolleyes:
 
You could use List(of T) and Contains...

Dim intArray() As Integer = {1, 2, 3, 4, 5}
Dim Integers As New List(Of Integer)(intArray)

Dim S as Integer = 2

If Integers.Contains(S) Then
    MsgBox("True")
End If
 
Last edited:
Menthos is correct but there's no need to create a List if you already have an array. Courtesy of LINQ, added in .NET 3.5, an array also has a Contains method. In VB 2010, the syntax is simplified considerably:
Dim s = 2

If {1, 2, 3, 4, 5}.Contains(s) Then
    '...
End If
 
Menthos is correct but there's no need to create a List if you already have an array. Courtesy of LINQ, added in .NET 3.5, an array also has a Contains method. In VB 2010, the syntax is simplified considerably:
Dim s = 2

If {1, 2, 3, 4, 5}.Contains(s) Then
    '...
End If


Thanks jmcilhinney... I should really leverage LINQ a lot more ;)
 
Thanks very much both of you. Thats an excellent alternative that i didn't even know about, but do now. I can see that getting used a lot :)

Thanks again.
 
Back
Top