We Recommend

Beginning VB.NET Beginning VB.NET
Visual Basic .NET is the latest version of the most widely used programming language in the world, popular with professional developers and complete beginners alike. This book will teach you Visual Basic .NET from first principles. You'll quickly and easily learn how to write Visual Basic .NET code and create attractive windows and forms for the users of your applications.


Posted By

rtipton on 06/05/09


Tagged

Delegate


Versions (?)


Simple Delegate Example


Published in: VB.NET 


  1. Imports System
  2. Namespace DelegateTest
  3. Public Delegate Sub TestDelegate(ByVal message As String)
  4.  
  5. Class Program
  6. Public Shared Sub Display(ByVal message As String)
  7. Console.WriteLine("")
  8. Console.WriteLine("The string entered is : " + message)
  9. End Sub
  10.  
  11. Shared Sub Main(ByVal args As String())
  12. '-- Instantiate the delegate
  13. Dim t As New TestDelegate(AddressOf Display)
  14.  
  15. '-- Input some text
  16. Console.WriteLine("Please enter a string:")
  17. Dim message As String = Console.ReadLine()
  18.  
  19. '-- Invoke the delegate
  20. t(message)
  21. Console.ReadLine()
  22. End Sub
  23. End Class
  24. End Namespace

Report this snippet 

You need to login to post a comment.