我有一个(posdata的)散列集,pos数据包含一个布尔值和一个包含hashkey的标签。我需要绘制一个condtion,它将检查两个或三个不同记录的布尔值是否不等于false。如果条件为真,我想将两个或三个记录的布尔值设置为false。这是一次尝试,
ElseIf (position.strLabel = "b2" And position.blnAvail <> False) And (position.strLabel = "b1" And position.blnAvail <> False) And (position.strLabel = "e1" And position.blnAvail <> False) Then
position.blnAvail = False ' trying to set the boolean to false
pos = position.strX & " " & position.strY
'position.blnAvail = False
count += 1
Bavailable = False'breaks out of the loop
答案 0 :(得分:0)
您可以使用扩展程序
简化代码<Extension()> _
Function IsAnyOf(ByVal s As String, ByVal ParamArray names As String()) As Boolean
Return names.Any(x => x.Equals(s))
End Function
然后您的代码可以重写为
If position.blnAvail <> False And not position.strLabel.IsAnyOf("b2", "b1", "e1") then
......
注意,我正在使用C#进行翻译,所以在某些地方语法可能不正确