Generic Constraints
-
Can not use in structs
-
A derivation constraint
-
A default constructor constraint
-
A reference/value type constraint
Generic constraints in C# restrict type parameters. Derivation constraints specify a base class, constructor constraints require a parameterless constructor, and reference/value type constraints constrain to class or struct. Generic constraints CAN be used with structs - they're not limited to classes.
C# generic type parameters support several kinds of constraints: a derivation constraint (where T : SomeBaseClass) restricting T to a specific class or its subclasses, a default constructor constraint (where T : new()) requiring a public parameterless constructor, and a reference/value type constraint (where T : class or where T : struct) restricting T to reference or value types respectively. Generic constraints can be used with structs/generic types generally, so 'cannot use in structs' is false.