views:

27

answers:

1

Such as:

mylist.FindAll(Function(item) item.property = variable)

The reason I ask is if I use syntax like this, I tend to get a string to whatevever conversion error, which makes me think "variable" is being treated literally as a string.

Thanks.

A: 

You can use anonymous function:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim lista As New List(Of My_Class)
  lista.Add(New My_Class With {.x = 1, .y = 0})
  For Each R In lista.FindAll(Function(V) V.x = 1)
      Debug.Print(R.y)
  Next
End Sub


End Class
Public Class My_Class
  Public x, y As Integer    
End Class
x77
When compares to a constant value, Vb generates as Lambda (Function)When compares to a local variable, Vb generates a Clousure (Class)
x77