Galin Iliev's blog

Software Architecture & Development

VB 9 Relaxed Delegates

I am reading about new features in Visual Studio 9.0 (Orcas) (while I am playing with it :) ) and I found there is a new feature in Visual Basic called Relaxed Delegates.

What this means!? For instance you can convert methods to delegate even when methods doesn;t have all parameters (if not used)

This is the sample from Amada Silver:

Another great feature that you’ll notice in Beta1 is Relaxed Delegates. In short, relaxed delegates are a way to extend VB’s implicit conversions to delegate types. With relaxed delegates, you can write the following code:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) _

  Handles Button1.Click, Button1.MouseClick

    MsgBox("Do Something")

End Sub

You can even omit *all* of the event arguments if your method body doesn’t need them. This improves readability without compromising type safety:

Option Strict On

Public Class Form1

  Private Sub Button1_Click() Handles Button1.Click, Button1.MouseClick

    MsgBox("Do Something")

  End Sub

End Class


A bit unfair to C# but still - this is Visual Basic :)


Loading