我声明了两个方法
public void MethodA(object o, Action<string> action) { }
public void MethodA(object o, Action<CustomType> action) { }
如何使用匿名方法调用这些函数?我知道我可以传递一个指向方法的指针,但我有兴趣使用匿名方法这样做吗?目前我收到错误消息“Ambitious call between...”
MethodA(this, c => { }); // how to explicitly say that C is of type CustomType?
最佳答案
MethodA(this, (CustomType c) => { });
或者如果您想将委托(delegate)类型显式声明为 Action<CustomType>
:
MethodA(this, (Action<CustomType>)(c => { }));
关于c# - 如何显式定义匿名方法符合什么签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11118370/