1. 委托 From: http://www.cnblogs.com/daxnet/archive/2008/11/08/1687014.html 类是对象的抽象,而委托则可以看成是函数的抽象.一个委托代表了具有相同参数列表和返回值的所有函数. class Program { delegate int CalculateDelegate(int a, int b); int add(int a, int b) { return a + b; } static void Main(string[]…
delegate event action func 匿名方法 lambda表达式 delegate类似c++的函数指针,但是是类型安全的,可以指向多个函数, public delegate void DelegateMethod(); //声明了一个Delegate Type public DelegateMethod delegateMethod; //声明了一个Delegate对象 var test = new TestDelegate(); test.delegateMethod = n…
前提:基于委托实现 (1)使用函数名称 delegate void Printer(string s);//(1)申明委托 static void Main(string[] args) { //(3)委托与命名方法关联 p = new Printer(DoWork); p("The delegate using the named method is called.");//(4)调用委托 Console.ReadKey(); } static void DoWork(string…
public delegate void ConsoleWriteStr(string name,DateTime now); public delegate int DelegateAdd(int x, int y); //第一步 使用匿名函数 ConsoleWriteStr cws1= new ConsoleWriteStr( delegate(string name, DateTime now){ Con…
一.一般委托方式 Func<int, int, int> AddMethodHander; public unName() { AddMethodHander += AddMethod; } public int AddMethod(int num1, int num2) { int result = num1 + num2; Console.WriteLine(result); return result; } public void Test1() { AddMethodHander.In…
1.lambda 匿名方法 匿名类型 delegate void d1(); d1 d = delegate(){Console.WriteLine("this is a test");}; //使用匿名方法 d1 d += ()=>{Console.WriteLine("this_test2");}; //使用lambda表达式 var q1 = new {name= "jing",age=25}; //匿名类型必须和var配合用 var…