Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*
- Declare the delegate. In this case, double is the return type that the handler
- must also mirror. The name of the delegate, SimpleDelegate, will be used to
- strongly type the variable that will hold the instance of the delegate. It will be of type SimpleDelegate, NOT double.
- */
- public delegate double SimpleDelegate(int a,int b);
- class Class1
- {
- // Declare the handler method, whose method signature must mimic that of the delegates.
- static double product(int i,int j)
- {
- return i*j;
- }
- static void Main(string[] args)
- {
- // Create the Delegate Instance, passing it the handler method.
- SimpleDelegate delObj = new SimpleDelegate(product);
- // Call the delegate instance, passing it the data you want the method handler to operate on.
- double res = delObj(1,2);
- Console.WriteLine("Result:" + " " + res);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement