I’m kind of going nuts here. I have a function something like the following. It’s failing to return an object. I can pass in a list, I can see in QuickWatch that x.RB = theRb for at least one of the items in the list, yet it doesn’t exit the loop (via the Return). The loop continues.
The list I am passing in is a subclass of aXXX.
Property RB on class aXXX is of type RBEnum.
Also, I originally used Linq for this but was getting “no matching items” exceptions.
Private Shared Function GetX(Of T As aXXX)(ByVal a As List(Of T),
ByVal theRb As RBEnum) As T
For Each x As T In a
If (x.RB = theRb) Then Return x
Next
Return Nothing
End Function
Any suggestions or ideas on why this isn’t working?
I have resolution. I can’t fully explain it though.
The list of items I’m passing in are a subclass of the class aXXX. The subclass did not properly override the
RBproperty from the base class — noOverloads/Overrides/Shadows. This kind of gives explanation as to why QuickWatch reports True on the match — maybe this subclass property was hiding the “real” property value that was in the test?Anyway, by taking out the property in the subclass all together or adding an
Overloads, the For Each behaves as one would expect. I can even go back to the original Linq version I had in the function.I guess this came down to oversight / sloppy coding on my part. But the issue was masked pretty well by the fact that QuickWatch reported “false positives”!
Thanks to everyone for the suggestions and help.