Curiously Recurring Template Pattern and generics constraints (C#)

This might work for you:

class Base<T> where T : Base<T>

You can’t constrain T to an open generic type. If you need to constrain T to Base<whatever>, you’ll need to construct something like:

abstract class Base { }

class Base<T> : Base where T : Base { ... }

Leave a Comment