Skip to content

Instantly share code, notes, and snippets.

@leppie
Created July 28, 2016 11:05
Show Gist options
  • Select an option

  • Save leppie/1caa5041a5b195a1502e37377c0b4cee to your computer and use it in GitHub Desktop.

Select an option

Save leppie/1caa5041a5b195a1502e37377c0b4cee to your computer and use it in GitHub Desktop.
class Program
{
// first argument needs to be a reference type...
public static int Add(object a, int b) => (int) a + b;
static void Main(string[] args)
{
var a = 1;
var add1 = (Func<int, int>)Delegate.CreateDelegate(typeof(Func<int, int>), a, typeof(Program).GetMethod("Add"));
Console.WriteLine(add1(2));
Console.WriteLine(add1(3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment