Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any IN Operator in VB.net functions like the one in SQL

Is there any function or operator like:

        If RoleName in ( "Val1",  "Val2" ,"Val2" ) Then
        'Go
    End If

Instead of:

    If RoleName = "Val1" Or RoleName = "Val2" Or RoleName = "Val2" Then
        'Go
    End If
like image 593
Alaa Avatar asked Nov 22 '12 13:11

Alaa


People also ask

What are the types of operators in Visual Basic?

Visual Basic provides the following types of operators: Arithmetic Operators perform familiar calculations on numeric values, including shifting their bit patterns. Comparison Operators compare two expressions and return a Boolean value representing the result of the comparison.

What does += mean in Visual Basic?

The += operator adds the value on its right to the variable or property on its left, and assigns the result to the variable or property on its left.


1 Answers

Try using an array and then you can use the Contains extension:

Dim s() As String = {"Val1", "Val2", "Val3"}
If s.Contains(RoleName) Then
  'Go      
End If

Or without the declaration line:

If New String() {"Val1", "Val2", "Val3"}.Contains(RoleName) Then
  'Go
End If

From the OP, if the Contains extension is not available, you can try this:

If Array.IndexOf(New String() {"Val1", "Val2", "Val3"}, RoleName) > -1 Then
  'Go
End If
like image 157
LarsTech Avatar answered Oct 18 '22 13:10

LarsTech