1

我声明了两种方法

public void MethodA(object o, Action<string> action) { }
public void MethodA(object o, Action<CustomType> action) { }

如何使用匿名方法调用这些函数?我知道我可以传递一个指向方法的指针,但我有兴趣使用匿名方法来做这件事吗?目前我收到错误“......之间的雄心勃勃的电话”

MethodA(this, c => { }); // how to explicitly say that C is of type CustomType?
4

1 回答 1

4
MethodA(this, (CustomType c) => { });

或者,如果您想将委托类型明确声明为Action<CustomType>

MethodA(this, (Action<CustomType>)(c => { }));
于 2012-06-20T11:19:42.397 回答