Partilhar via


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

    arrInt.Add(i)

Next

 

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.

 

Namoskar!!!

Comments

  • Anonymous
    February 05, 2008
    In VB.NET 9.0 Lambda is one of the features we have here. Lambda expression is just another way to call

  • Anonymous
    January 09, 2009
    Thanks.  Was trying to figure out the syntax for lambda expression in vb.net as i'm a c# guy.

  • Anonymous
    September 23, 2009
    Nice, How do I convert thefollowing c# code to VB.Net using Lambda Expression: synchronizationContext.Post((e) => action((T)e), eventArgs); THanks Atallah

  • Anonymous
    October 07, 2009
    The comment has been removed

  • Anonymous
    February 10, 2010
    synchronizationContext.Post((Function(e as T) action(e)), eventArgs)

  • Anonymous
    June 30, 2010
    Very Good! Thanks you very much! Now I understand on 'Lambda' clearly.

  • Anonymous
    July 02, 2011
    sir,    i need to generate bill number VB.NET 2008 like ( dkv000, dkv001, dkv002 ) then next day it should continue with next bill number followed by previous number