How to explicitly define what signature does anonymous method conform to?
-
15-06-2021 - |
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?
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