Simple Delegate Example


/ Published in: VB.NET
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.