我有一个仅迭代 1 个元素的 For Each 循环。它从我的测试中 32 个元素中的第 6 个元素开始,恰好是 comp.includeMe 评估为 True 的元素。执行外部 if 语句后,它开始第二次迭代,但退出循环并在 comp.includeMe 评估为 false 后立即返回。不存在错误或警告,并且我已验证组件对象中有元素。谁能解释我做错了什么,以及为什么这种语法不起作用?
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)