-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Ritesh_Kesharwani
Message 4 in Discussion

Hi,   See the Example of Delegate..   Delegates is perhaps one of the powerful feature 
.NET has introduced in C#, VB.NET and other languages. Delegates serve the same 
purpose as function pointers in c++ but they are type-safe. Delegates can be used in 
many ways, the following example shows the use of delegates as function pointers. 

Option Strict Off 'This Option tells the compiler not to check Type conversions
Imports system
Imports microsoft.visualbasic
 
    Class MyDelegate
      Delegate Sub dg()

      Shared Sub main()
        'Declare variables of delegate type
        Dim i dg
        'make i point the sub Hi
        i = AddressOf Hi <o:p></o:p>  
      End Sub

      Shared Sub Hi()
        msgbox("Hi")
      End Sub
    End Class<o:p></o:p> 
This code when compiled and run would result into a message box displaying "HI" 
Delegates could also point to two function, sounds interesting check this 
out.<o:p></o:p> 
Option Strict Off 'This Option tells the compiler not to check Type conversions
Imports system
Imports microsoft.visualbasic
 
      Class MyDelegate
        Delegate Sub dg()

        Shared Sub main()
          'Declare variables of delegate type
          Dim i, a, y As dg
          'make i point the sub Hi
          i = AddressOf Hi
          'make a point to Bye
          a = AddressOf Bye
          'combine the two delegates 
          y = System.Delegate.Combine(i, a)
          'invoke the delegate
          y()
        End Sub

        Shared Sub Hi()
           msgbox("Hi")
        End Sub

        Shared Sub Bye()
          msgbox("Bye")
        End Sub

End Class

This code when compiled and run will result in Two Message boxes invoked from the same 
delegate y().    
Regard's 
Ritesh Kesharwani 
Aditi Technology Pvt. Ltd. Bangalore. 
<o:p></o:p> 

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to