Advertisement
Guest User

Untitled

a guest
May 25th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. using System;
  2. /*
  3. Declare the delegate. In this case, double is the return type that the handler
  4. must also mirror. The name of the delegate, SimpleDelegate, will be used to
  5. strongly type the variable that will hold the instance of the delegate. It will be of type SimpleDelegate, NOT double.
  6. */
  7. public delegate double SimpleDelegate(int a,int b);
  8.  
  9. class Class1
  10. {
  11.  
  12. // Declare the handler method, whose method signature must mimic that of the delegates.
  13.  
  14. static double product(int i,int j)
  15. {
  16. return i*j;
  17. }
  18.  
  19.  
  20. static void Main(string[] args)
  21. {
  22. // Create the Delegate Instance, passing it the handler method.
  23. SimpleDelegate delObj = new SimpleDelegate(product);
  24.  
  25. // Call the delegate instance, passing it the data you want the method handler to operate on.
  26. double res = delObj(1,2);
  27.  
  28. Console.WriteLine("Result:" + " " + res);
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement