© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
33 replies
Kenji

✅ Recursive type definition

This is valid (basically CRTP):
class Base<T> { }
class Derived<T> : Base<Derived<T>> { }
class Base<T> { }
class Derived<T> : Base<Derived<T>> { }


This is not, because if you instantiate anywhere a
new Derived<SomeType>()
new Derived<SomeType>()
, the program panics with
TypeLoaderException
TypeLoaderException
because of "recursive generic definition"

class Base<T> { }
class Derived<T> : Base<Derived<Derived<T>>> { }
class Base<T> { }
class Derived<T> : Base<Derived<Derived<T>>> { }


I cannot understand the different between these two generic definitions.
If I specify
SomeType
SomeType
, I would imagine that the generics should expand as expected and resolve the types correctly, as kind-0 types, e.g.:
Derived<int> : Base<Derived<Derived<int>>>
Derived<int> : Base<Derived<Derived<int>>>


The only thing I could find is the official explanation on the CLI Standard here on page 129 https://www.ecma-international.org/publications-and-standards/standards/ecma-335/, but I do not quite get it. 🙂

Any ideas?
Ecma InternationalElisa Denis
ECMA-335 - Ecma International
Common Language Infrastructure (CLI) - Defines the infrastructure in which applications written in multiple high-level languages can be executed
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Recursive Multiplier
C#CC# / help
3y ago
❔ VSCode shows type definition and not the actually implementation
C#CC# / help
3y ago
Fibonacci in recursive ?
C#CC# / help
4y ago
Debugging recursive algorithms
C#CC# / help
4y ago