O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generic Delegates

With the introduction of multi-line statement lambdas, program code will be considerably different in the future. For example, multi-line statement lambdas have the advantage of letting you write event-handling code directly at the location where the event is bound, as the following example illustrates:

Public Class Form1

    Sub New()

        ' This call is required for the Designer.
        InitializeComponent()

        Dim MessageText As String = "Button1 was clicked"

        ' Add initializations after the InitializeComponent() call.
        AddHandler Button1.Click, Sub(sender As Object, e As EventArgs)
                                      MessageBox.Show(MessageText)
                                  End Sub
    End Sub

End Class

You can see here that the Click event is already coded in the constructor of the form. The multi-line lambda is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required