Limitations are good when you need information about the generic type argument. By restricting a type, you not only limit the set of valid type arguments, but also allow yourself to make decisions at compile time based on the common elements of this type set.
In your specific example, a general restriction does not give any benefit, but in other circumstances they may. Consider this example:
T foo<T>() { return null; }
This method cannot compile because the compiler knows (as it should when I wrote the method) that the generic type argument can be a value type that cannot be set to null . By adding a constraint, I can compile this code:
T foo<T>() where T : class { return null; }
Now I have limited a valid set of arguments of a general type to classes only. Since the compiler now knows that T must be a class, it allows me to return null , since there are no scripts in which null cannot be returned. Although this is not a very useful example, I am sure that you can extrapolate in ways that can be useful.
source share