Sometimes I encounter cases where I have to attach a method to a delegate but the signature doesn't match, like trying to attach abc down there to somedelegate with the string parameter being "hi".
public class test
{
//...
public void abc(int i, string x)
{
//Do Something
}
//...
}
public class test2
{
somedelegate x;
//...
public test2()
{
//Do Something
test y = new test();
x += y.abc(,"hi");
}
delegate void somedelegate(int i);
}
I can work it around by creating another delegate with the correct signature then attaching it but it seems so unnecessarily complex. Can you do something like this in C#? Thanks.
Right. I guess there is no way to do it as I envisioned but I can still do it simply like x += (int i) => abc(i, "hi");. So no problem now and thanks guys.
Just Googling for '.net delegate optional parameters' returns some results that may be useful:
Update (researching this some more, and helped by the first link above):
Could you perhaps use the Invoke method, which accepts any delegate?
Yes, you can do this with closures
[there's a nice treatment of the subject on msdn, but like anything else in there it's hard to find]
The Big Picture
Yes, this is a bit Matrix-y. But way cool.