Skip to content

Instantly share code, notes, and snippets.

@jmsevold
Last active May 25, 2016 15:32
Show Gist options
  • Save jmsevold/40aec5207c4a77461bb41f0fc388a403 to your computer and use it in GitHub Desktop.
Save jmsevold/40aec5207c4a77461bb41f0fc388a403 to your computer and use it in GitHub Desktop.
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