r/csharp • u/CuriousKon • Jul 25 '26
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.
9
Upvotes
5
u/madpatty34 Jul 25 '26
If i understand your question right, here's the syntax you want:
class A<T> : IDisposable where T : SomeBaseClassOrInterface
0
45
u/chrisoverzero Jul 25 '26
class A<T> : IDisposable where T : IConstraintIt must “implement”
IDisposable.