For Each
用于处理
DenialReason
s。这仍然感觉像一个黑客,但我认为它可能会更干净,你所拥有的。如果使用此代码,则不需要以开头的代码
If count = 1...
:
Dim count As Integer = 0
Dim index As Integer = 1
For Each item As String In reasons
If item = "True" Then
count += 1
Select Case count
Case 1
DenialReason1 = index.ToString()
Case 2
DenialReason2 = index.ToString()
Case 3
DenialReason3 = index.ToString()
End Select
End If
index += 1
Next
index
IndexOf()
.
我认为一个更好的解决办法是列出
拒绝理由
s并添加到该列表中,因为项为真:
Dim count As Integer = 0
Dim index As Integer = 1
Dim denialReasons As New List(Of String)()
For Each item As String In reasons
If item = "True" Then
denialReasons.Add(index)
End If
index += 1
Next
然后您可以简单地遍历
denialReasons
. 这是灵活的,所以无论出于什么原因,如果你有三个以上
拒绝理由