I'm trying to replace the classic For Each
loop with the LINQ ForEach
extension in VB.NET...
Dim singles As New List(Of Single)(someSingleList)
Dim integers As New List(Of Integer)
For Each singleValue In singles
integers.Add(CInt(Math.Round(singleValue)))
Next singleValue
Maybe something like this?
singles.ForEach(Function(s As [Single]) Do ???
How can I correctly do this using anonymous methods (i.e. without declare a new function)?
Try this:
singles.ForEach(Sub(s As [Single]) integers.Add(CInt(Math.Round(s))))
You need a Sub
here, because the body of your For Each
loop doesn't return a value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With