Reputation: 360
How do I convert this "java wildcards" to C# format?
public abstract class AAA<T extends BBB<?>> extends CCC<T>{}
My incorrect C# code
public abstract class AAA<T> : CCC<T> where T : BBB<?>{}
How do I convert BBB<?>
Upvotes: 3
Views: 162
Reputation: 548
There is a similar question C# generic "where constraint" with "any generic type" definition? not specific to Java wildcards. The answer provided there will likely help you.
From that answer, a possible class signature would be:
public abstract class AAA<T, TOther> : CCC<T>
where T : BBB<TOther>
{}
Generics in C# must have named type parameters even if you never plan to use the type explicitly/implicitly. And all type parameters must be named in the identifier declaration of the method/class/interface.
Note that it would be possible to constrain TOther to just object types if so desired using:
public abstract class AAA<T, TOther> : CCC<T>
where T : BBB<TOther>
where TOther : object
{}
Upvotes: 1
Reputation: 19682
What is BBB
exactly?
I bet that BBB<Object>
probably would work; BBB
is likely a covariant type.
Upvotes: 0