什么是lambda(函数)?对于一个没有计算机科学背景的人来说,在计算机科学的世界里,什么是“羔羊”(Lambda)?
3 回答
四季花海
TA贡献1811条经验 获得超5个赞
public Int32 Add(Int32 a, Int32 b){ return a + b;}public Int32 Sub(Int32 a, Int32 b){ return a - b;}public delegate Int32 Op(Int32 a, Int32 b);public void Calculator(Int32 a, Int32 b, Op op){ Console.WriteLine("Calculator: op(" + a + ", " + b + ") = " + op(a, b));}public void Test(){ Calculator(10, 23, Add); Calculator(10, 23, Sub);}
public delegate Int32 Op(Int32 a, Int32 b);public void Calculator(Int32 a, Int32 b, Op op){ Console.WriteLine("Calculator: op(" + a + ", " + b + ") = " + op(a, b));}public void Test(){ Calculator(10, 23, delegate(Int32 a, Int32 b) { return a + b; }); Calculator(10, 23, delegate(Int32 a, Int32 b) { return a - b; });}
public delegate Int32 Op(Int32 a, Int32 b);public void Calculator(Int32 a, Int32 b, Op op){ Console.WriteLine("Calculator: op(" + a + ", " + b + ") = " + op(a, b));}public void Test(){ Calculator(10, 23, (a, b) => a + b); Calculator(10, 23, (a, b) => a - b);}
添加回答
举报
0/150
提交
取消