views:

66

answers:

2

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 );
+3  A: 

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).

Kevin
+2  A: 

You can probably use Generic Delegates.

public delegate void Output<T1,T2>(T1 x, T2 y);
Yogendra