VB.NET 9.0: Lambda Expression

In VB.NET 9.0 Lambda is one of the features we have here. Lambda expression is just another way to call Anonymous method/delegate.


Let’s look into a generic list of integers, and play with it,


Dim arrInt As New List(Of Integer)

For i As Integer = 1 To 10




When you need to get the even numbers out of this List, you can call delegate,


Dim even1 As New List(Of Integer)

even1 = arrInt.FindAll(New Predicate(Of Integer)(AddressOf EvenGetter))


Then for this approach you need a method,

Public Function EvenGetter(ByVal i2 As Integer) As Boolean

    Return i2 Mod 2 = 0

End Function


Using VB.NET 9.0 you can also implement Lambda Expression,


even1 = arrInt.FindAll(Function(i2 As Integer) i2 Mod 2 = 0)


Ask expert for more.