1 つの要素のみを反復する For Each ループがあります。私のテストでは、32 個の要素のうち 6 番目の要素から始まり、たまたま comp.includeMe が True と評価される要素です。外側の if ステートメントが実行された後、2 回目の繰り返しが開始されますが、ループを終了し、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)