C#中λ表达式
时间:2010-10-23 来源:sunzongbao2007
using System;
class B
{
public delegate string Make();
public delegate string Reply(string str);
public static void Main(){
Make m= A.make;
Reply r = (str => A.reply(str));//λ表达式 现在r(string str)就代表A.reply(string str)
Console.WriteLine(kk(m));
Console.WriteLine(r("bingo reply"));
}
public static string kk(Make mm){
return mm();
}
}
class A
{
public static string make(){
return "A make";
}
public static string did(){
return "A did";
}
public static string pick(){
return "A pick";
}
public static string reply(string str){
return str;
}
}
=========================================
λ表达式也可以做匿名方法
例如
delegate bool Method(int x,int y);
static void Main(){
Method method=(x,y)=>
{
return x>y;
};
Console.WriteLine(method(1,2));
}
输出 false
相关阅读 更多 +