DLR的奇怪行为.我有一个方法接受两个参数:dynamic和Func <>.当我只传递动态OR只有Func <> - 没有错误.但是当我尝试同时传递这些参数时 - 出现错误"无法将lambda表达式用作动态调度操作的参数,而无需先将其转换为委托或表达式树类型.":
static void Main(string[] args)
{
dynamic d = 1;
Method1(d);// - OK
Method2(f => 1);// - OK
Method3(d, f => 1);// - Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.
}
static void Method1(dynamic d)
{
}
static void Method2(Func<string, int> func)
{
}
static void Method3(dynamic d, Func<string, int> func)
{
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
当然我可以进行明确的转换,并且错误消失了:
Method3(d, (Func<string, …Run Code Online (Sandbox Code Playgroud)