是否有任何函数或运算符,例如:
If RoleName in ( "Val1", "Val2" ,"Val2" ) Then
'Go
End If
代替:
If RoleName = "Val1" Or RoleName = "Val2" Or RoleName = "Val2" Then
'Go
End If
尝试使用数组,然后您可以使用 Contains 扩展:
Dim s() As String = {"Val1", "Val2", "Val3"}
If s.Contains(RoleName) Then
'Go
End If
或者没有声明行:
If New String() {"Val1", "Val2", "Val3"}.Contains(RoleName) Then
'Go
End If
在 OP 中,如果 Contains 扩展不可用,您可以尝试以下操作:
If Array.IndexOf(New String() {"Val1", "Val2", "Val3"}, RoleName) > -1 Then
'Go
End If
In
您可以使用如 LarsTech 所示的 Contains,但添加扩展方法也很容易:
Public Module Extensions
<Extension()> _
Public Function [In](Of T)(value As T, ParamArray collectionValues As T()) As Boolean
Return collectionValues.Contains(value)
End Function
End Module
你可以像这样使用它:
If RoleName.In("Val1", "Val2", "Val3") Then
'Go
End If
您还可以使用以下Select..Case
语句:
Select Case RoleName
Case "Val1", "Val2", "Val3"
' Whatever
End Select