转换为lambda

use*_*800 0 c# lambda

如何将以下内容转换为Lambda?

Func<int, string> calcState = delegate(int test) 
    { 
        return (!MyList.All(i => i > test) ? 
            (MyList.Any(i => i > test) ? "ein Paar" : "Keiner") : "alle"); 
    };
Run Code Online (Sandbox Code Playgroud)

Ser*_*kiy 5

删除delegatereturn关键字.您也不需要指定参数类型 - 它将被推断:

Func<int, string> calcState = 
   test => (!MyList.All(i => i > test) ? (MyList.Any(i => i > test) ? "ein Paar" : "Keiner") : "alle");
Run Code Online (Sandbox Code Playgroud)

进一步阅读:表达Lambda

  • 显然在那里有一个反lambda运动:) (2认同)