Created
July 28, 2016 11:05
-
-
Save leppie/1caa5041a5b195a1502e37377c0b4cee 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
| 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