VB.NET 10 : Multiline Lambdas

With implicit line continuation VB.NET 10 now allows you to write the multiline Lambdas. That means like your normal Functions you can write functions under Lambdas.

So now you may write like,

Dim arrInt As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Dim myFinc = Array.FindAll(arrInt, Function(n)

                                       If n Mod 2 = 0 Then

                                           Console.WriteLine("{0} is Even", n)

                                       Else

                                           Console.WriteLine("{0} is not Even", n)

                                       End If

                                   End Function)

 

Namoskar!!!

Comments

  • Anonymous
    November 08, 2009
    Does it support "non-function lambdas", that is, lambdas that do not return a value?

  • Anonymous
    November 10, 2009
    Nice post, it is really helpful. which version onwards it is supported .

  • Anonymous
    December 05, 2010
    I use lamda to fill properties of a class in the constructor, the only way i have been able to do tjis is to return the object and then assign the values to the propeties, what i want to do is assign the values without returning the object. here is a test class I made to show you what i am trying to do, but this code does not work. What am i doing wrong? Public Class Test    Public Property Heading As String    Public Property Url As String    Public Sub New(ByVal id As Integer)        Using em As SEOEE.SEODBEntities = New SEOEE.SEODBEntities            em.Articles.Where(Function(w) w.ArticleId = id).Select(Sub(s)                                                                       Me.Heading = s.Heading                                                                       Me.Url = s.Url                                                                   End Sub).SingleOrDefault()        End Using    End Sub End Class Any ideas? Thanks