我有一個For Each循環只迭代1個元素。它從我測試中的第6個元素開始,恰好是comp.includeMe評估爲True的一個元素。在執行外部if語句之後,它將開始第二次迭代,但會退出循環並在comp.includeMe計算結果爲false後立即返回。不存在錯誤或警告,並且我已驗證組件對象中有元素。任何人都可以解釋我做錯了什麼,爲什麼這個語法不起作用?爲每個循環VB.NET退出一次迭代後
Public Class BOM
Public Property components as New List(Of Component)
Public Function TotalArea(ByVal adjusted As Boolean) As Double
Dim total As Double = 0
For Each comp As Component In components
If comp.includeMe = True Then
If adjusted Then
total += comp.GetAdjustedSize() * comp.quantity
Else
total += comp.area * comp.quantity
End If
End If
Next
Return total
End Function
public sub Add(byval comp as Component)
components.add(comp)
end sub
End Class
Public Class Component
Public Property quantity as Integer
Public Property area as Double
Public Property includeMe as Boolean
...
End Class
' object construction
Dim bomlist as New BOM
bomlist.add(comp)
在哪裏初始化'components'? –
當BOM類被構造時,一個列表被傳入 –
我已經驗證了調試器組件中實際上有值。沒有丟失 –