2012-06-20 97 views
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
MethodA(this, (CustomType c) => { }); 

,或者如果你想明確說明委託類型爲Action<CustomType>

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