我有一个方法,其签名如下:
void MyMethod(Delegate d){};
void MyMethod(Expression exp){};
void MyMethod(object obj){};
然而,这个无法编译:
MyMethod((int a) => a)
以下是错误信息:
"Cannot convert lambda expression to type 'object' because it is not a delegate type"
为什么这个不起作用?
编辑:我知道这个可以工作。在这种情况下,编译器将lambda表达式编译为委托。
void MyMethod(Func<int, int> d){};
此致敬礼,