转载weixin_33713707 发布于2019-05-05 16:21:00 阅读数 35 收藏
匿名方法是用来创建委托实例的,下面来看一下具体的事例
1 namespace DeletateAndEvent 2 { 3 //创建委托 4 delegate int AddDelegate(int a,float b); 5 delegate double AddDelegateD(float a,double b); 6 class Program 7 { 8 static void Main(string[] args) 9 { 10 AddDelegate ad = delegate(int i, float f)//匿名方法 11 { return i + (int)f; }; 12 int a = ad(20,12.5f); 13 Console.WriteLine(a); 14 15 AddDelegateD add = delegate(float f,double d) 16 { return f * d; }; 17 double dd = add(10,20); 18 Console.WriteLine(dd); 19 20 ///下面这个方法就有点不理解了 21 ad = delegate 22 { return 12 + 12; }; 23 a = ad(0,0); 24 Console.WriteLine(a); 25 } 26 } 27 }
转载于:https://www.cnblogs.com/fllowerqq/p/10813658.html