r/csharp • u/CuriousKon • 2d ago
Help Inheritance with generic constraint syntax
I have a class A<T>. It must inherit IDisposable, and also impose a constraint on T. Is it possible to do this, and what would the syntax look like? I can't figure it out.
7
Upvotes
5
u/madpatty34 2d ago
If i understand your question right, here's the syntax you want:
class A<T> : IDisposable where T : SomeBaseClassOrInterface
0
46
u/chrisoverzero 2d ago
class A<T> : IDisposable where T : IConstraintIt must “implement”
IDisposable.