tags:

views:

109

answers:

1

Hi,

There is a piece of code that I would implement like this in java:

public void doIt( T extends MyEventArgs<? extends MyBaseClass> obj ) {
   ...
}

How would I do that in c#? I first thought this would be it:

public void oIt( T obj ) where T : MyEventArgs<P> where P : MyBaseClass {
    ...
}

But apparantly my syntax is wrong.

any ideas?

PS: don't ask me why I'm doing this. Please :)

+11  A: 

Just missing the generic type arguments:

public void oIt<T,P>( T obj )
     where T : MyEventArgs<P>
     where P : MyBaseClass
{
     ...
}

(the names oIt, T, P and obj could probably be clearer, but I'll assume that is anonymisation)

Marc Gravell
By the way, the compiler won't be able to infer the type parameters for you if you do this. You should manually specify both T and P when you call the method.
Mehrdad Afshari