Posted By

rtipton on 06/05/09


Tagged

Delegate


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

umang_nine
vali29
rageit
markstahler


Simple Delegate Example


 / Published in: C#
 

  1. using System;
  2. namespace DelegateTest
  3. {
  4. public delegate void TestDelegate(string message);
  5.  
  6. class Program
  7. {
  8. public static void Display(string message)
  9. {
  10. Console.WriteLine("");
  11. Console.WriteLine("The string entered is : " + message);
  12. }
  13.  
  14. static void Main(string[] args)
  15. {
  16. //-- Instantiate the delegate
  17. TestDelegate t = new TestDelegate(Display);
  18.  
  19. //-- Input some text
  20. Console.WriteLine("Please enter a string:");
  21. string message = Console.ReadLine();
  22.  
  23. //-- Invoke the delegate
  24. t(message);
  25. Console.ReadLine();
  26. }
  27. }
  28. }

Report this snippet  

You need to login to post a comment.