We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

rtipton on 06/05/09


Tagged

Delegate


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

umang_nine
vali29


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.