using System; using System.Collections.Generic; using System.Text; using LinFu.Delegates; namespace BindingAndUnbindingClosureParameters { class Program { static void Main() { CustomDelegate addMethodBody = delegate(object[] args) { int a = (int)args[0]; int b = (int)args[1]; return a + b; }; // Define the method signature Type returnType = typeof(int); Type[] parameterTypes = new Type[] { typeof(int), typeof(int) }; // Notice that the original parameters use 1 + 1 Closure closure = new Closure(addMethodBody, returnType, parameterTypes, 1, 1); // Change the value of the second parameter to �3� closure.Arguments[1] = 3; // This will return �4� instead of �2� int result = (int)closure.Invoke(); Console.WriteLine("The result is {0}", result); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)