Given:
delegate void Explicit();
Can I:
public void Test(Explicit d)
{
Action a;
a = d; // ????
}
I have a scenario where I need to overload a constructor that has:
public MyClass(Expression<Action> a) {}
but the following overload is ambiguous:
public MyClass(Action a) {}
I figured using an explicit delegate would resolve the ambiguity but I need to cast that explicit delegate to an action in order to leverage the existing code.
Action a = new Action(d);
No you cannot cast different delegate types with matching signatures between each other. You must create a new delegate / lambda expression of the target type and forward into the original one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With