开发者

Overload Anonymous Functions

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


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


You can probably use Generic Delegates.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜