Last active
May 25, 2016 15:32
-
-
Save jmsevold/40aec5207c4a77461bb41f0fc388a403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment