![]() |
|
|
Relaxed Delegates. VB 2008 / VB 9.0 |
Post Reply
|
| Author | |
Jijo
Admin Group
Joined: 31 Dec 05 Location: United Kingdom Posts: 495 |
Quote Reply
Topic: Relaxed Delegates. VB 2008 / VB 9.0Posted: 03 Sep 07 at 10:02am |
|
Relaxed Delegates.
Let me start to explain basics of relaxed delegates Have you ever tried to have same function written for Button Click event of 2 different Buttons?? Its easy isn't? Just like the code below Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click, Button2.Click MsgBox("Do Something") End Sub Is it working?? Yes so try to change 'Sub Button1_Click' to 'Sub ooooClick' Now also its working. So the same function can be attached to different button and its actually 'Handles Button1.Click, Button2.Click' that does the job So what if we try to make Button Click and Button Mouse Click together, Noooooo!! It shows an error that it is of different signature. But with VB 2008 you can do that and thats 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 This is just the basic of Relaxed delegates... Hope that it would have helped newbies.. What is new in VB 2008
What are Extension Method
Partial Methods in C# 3.0 and VB.net 9.0
Nullable Types in VB 2008 & VB 2005
IIf in VB2005 vs IF in VB2008 - Whats new in VB9.0
|
|
![]() |
|
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |