为什么这个 lambda 函数需要括号?

Why are parentheses needed around this lambda function?

return (Func<object, Task<object>>)(async (dynamic data) =>
{
    methodCall(data.data, data.more);
    return null;
});

根据我收集到的上述代码所做的,它显式地将 lambda 函数转换为委托,然后返回该委托(在本例中,它返回到 edgejs 函数)。

删除括号后,从构建过程中收到 8 个错误。

Syntax error, ',' expected

; expected

} expected

The name async does not exist in the current context

The name dynamic does not exist in the current context

The name data does not exist in the current context

The name data does not exist in the current context

The name data does not exist in the current context

可能是因为 async is a contextual keyword 只有在方法或 lambda 签名中作为修饰符出现时才具有特殊含义。没有括号,解析器认为 async 是一个方法名,导致错误,因为编译器找不到具有该名称的方法(并且,进一步, => 上的解析错误,因为解析器是此时不再使用 lambda 表达式)。