Generic constraints to a specific class, why? [duplicate]
问题 This question already has answers here : Why use generic constraints in C# (7 answers) Closed 6 months ago . I've been reading on leveraging generic constraints, I've found that generics can be constrained to struct , class , new , Class and Interface . The reasons behind the first three are pretty obvious. But I can't really understand why and when to constraint to a class. i.e class Foo<T> where T : Bar class Foo<T> where T : IBar This allows us to constrain to Bar and it's children, and