Question

I have two methods declared

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

How can I call these functions using anonymous method? I know I can pass a pointer to a method, but I am interested in doing this using anonymous method? Currently I am getting error "Ambitious call between....."

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

Solution

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

or if you want to explicitly state the delegate type as Action<CustomType>:

MethodA(this, (Action<CustomType>)(c => { }));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top