This fails
string temp = () => {return \"test\";};
with the error
Cannot convert lambda expression to type \'str
Using a little helper function and generics you can let the compiler infer the type, and shorten it a little bit:
public static TOut FuncInvoke(Func func)
{
return func();
}
var temp = FuncInvoke(()=>"test");
Side note: this is also nice as you then are able to return an anonymous type:
var temp = FuncInvoke(()=>new {foo=1,bar=2});