Reputation: 12441
Is it possible to create an inline delegate in vb.net like you can in c#?
For example, I would like to be able to do something inline like this:
myObjects.RemoveAll(delegate (MyObject m) { return m.X >= 10; });
only in VB and without having to do something like this
myObjects.RemoveAll(AddressOf GreaterOrEqaulToTen)
Private Function GreaterOrEqaulToTen(ByVal m as MyObject)
If m.x >= 10 Then
Return true
Else
Return False
End If
End Function
-- edit -- I should have mentioned that I am still working in .net 2.0 so I won't be able to use lambdas.
Upvotes: 21
Views: 11925
Reputation: 3208
myObjects.RemoveAll(Function(m As MyObject) m.X >= 10)
See Lambda Expressions on MSDN
Upvotes: 29
Reputation: 19793
Try:
myObjects.RemoveAll(Function(m) m.X >= 10)
This works in 3.5, not sure about the 2.0 syntax.
Upvotes: 7