For lambda expresssion ()=>getItem("123")
, is it Func(bool开发者_运维问答) or Func(string,bool), suppose getItem return bool.
It's a Func<bool>
.
The clue is in the () =>
part: This means that the function has no input parameters.
If you want to refactor this to a Func<string,bool>
then pull the literal "123" out and treat it as an input parameter instead:
bool getItem(string input) { ... }
Func<bool> selector = () => getItem("123");
Func<string,bool> selector2= str => getItem(str);
bool result1 = selector();
bool result2 = selector2("123");
Assert.AreEqual(result1,result2);
Strictly speaking, the answer is neither. Lambda expressions are typeless
精彩评论