There are two differences between using
where T : struct
and
where T : ValueType
- the latter might
T be a ValueType itself, which is a reference type. - the latter would also allow
T a value type with a zero value
The first of these differences is almost never what you want. This can sometimes be useful; Nullable<T> bit odd in that it satisfies neither the where T : struct nor where T : class constraint.
A more useful limitation would be
where T : struct, System.Enum
which is forbidden by C # for any good reason I can say. See my blog post and Non Tune Design for more information on this.
Jon Skeet Dec 06 '09 at 8:21 2009-12-06 08:21
source share