After failing to get something like the following to compile:
public class Gen<T> where T : System.Array
{
}
with the error
A constraint cannot be special class `System.Array'
I started wondering, what exactly is a "special class"?
People often seem to get the same kind of error when they specify System.Enum
in a generic constraint. I got the same results with System.Object
, System.Delegate
, System.MulticastDelegate
and System.ValueType
too.
Are there more of them? I cannot find any info on "special classes" in C#.
Also, what is so special about those classes that we can't use them as a generic type constraint?
According to MSDN it's a static list of classes:
Compiler Error CS0702
Constraint cannot be special class 'identifier' The following types may not be used as constraints: