bananatop
bananatop

Reputation: 1

What's the syntax to derive a generic class from another generic class when both have constraints?

I have a base generic class defined as follows:

public class TheBaseClass<T> where T : Interface1 {}

I have another generic class that I'd like to derive from TheBaseClass. It's defined as follows:

public class SomeClass<T> where T : Interface2 {}

I've looked through the docs, but I can't find an example that compiles. All suggestions will be gratefully received.

Upvotes: 0

Views: 29

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236278

When you are inheriting generic base class, you should specify base class constraints for generic type parameter as well:

public class SomeClass<T> : TheBaseClass<T>
 where T : Interface1, Interface2
{}

Upvotes: 1

Related Questions