Reputation: 21178
Still wrapping my head around Delegates and I'm curious: Is it possible to overload anonymous functions?
Such that:
delegate void Output(string x, int y);
Supports:
Output show = (x, y) => Console.WriteLine("{0}: {1}", x.ToString(), y.ToString());
And:
delegate void Output(string x, string y);
Allowing:
show( "ABC", "EFG" );
And:
show( "ABC", 123 );
Upvotes: 1
Views: 278
Reputation: 2919
You can probably use Generic Delegates.
public delegate void Output<T1,T2>(T1 x, T2 y);
Upvotes: 3
Reputation: 115420
No you can't overload a delegate like that.
This is a type
delegate void Output(string x, int y);
changing it to this:
delegate void Output(string x, string y);
would redefine it.
It would be kinda like defining two different classes with the same name (in the same namespace).
Upvotes: 3