Recursive generic type parameter in C#

Viewed 468

I needed some help understanding recursive generics in C#.

I came across this code:

public abstract class Value<T> where T : Value<T>
{
    ....
}

public class UserId: Value<UserId>
{
}

I am confused by the part where the Value<T> is used on both sides of the where clause. Can someone please explain what the code does?

2 Answers

It a recursive generic type parameter.

It means that T must be a Value of T.

It is normal to found that difficult to understand and I found it is difficult to explain... sorry.

Someone else should be able to explain better.

Recursive Generics

Recursive Generics Restrictions

Related