我总共有102个值与名为ArrivedFlag
的字段名相关联。是否有更有效的方法来管理IF语句?
然后我在标记页上有一个TextBox
控件,其ID为txtFlag
。
在我隐藏,我有一个if语句,说:
If txtFlag <> "value1" and txtFlag <> "another value" Then
lblMessage.Text ="You don't have the ability to view details"
end if
这工作得很好。
但是,考虑到有102个值,我觉得做102次IF语句有点低效。
有没有人知道更好的方法来处理这个问题?
Dim allowedFlags = New List(Of String)()
With { _
"value1", _
"another value"
}
End With
If Not allowedFlags.Contains(txtFlag) Then
lblMessage.Text = "You don't have the ability to view details"
End If
经过一些微小的修改后,这对我来说效果很好。谢谢你,感谢所有贡献者。 – Kenny