views:

30

answers:

1

I have a delegate

delegate string Mathop<T,F>(T a,F b); 

and I am declaring an event like

event Mathop<T,F> someevent;

But here I am getting an error. It says 'T' could not be found. I want my Mathop delegate to work as an eventhandler for my event.

What I am doing wrong here.

+2  A: 

You need to enclose the event in a class which takes type parameters e.g.

class C<T, F>
{
    event Mathop<T, F> someevent;
}

You can't subscribe to an event that doesn't have concrete types defined - imagine if you could - you could add any delegate to that event as long as it took two parameters and returned a string!

With the above code, you should now be able to do something like

new C<Int32, Int32>().someevent += MyMethod

where MyMethod has the signature

String MyMethod(Int32 a, Int32 b);
Alex Humphrey
+1 @Alex Perfect. I have been able to resolve it.
vaibhav