What exactly is a “Special Class”?

后端 未结 7 1956
鱼传尺愫
鱼传尺愫 2020-12-23 13:21

After failing to get something like the following to compile:

public class Gen where T : System.Array
{
}

with the error

7条回答
  •  梦毁少年i
    2020-12-23 13:40

    The following can be found in CLR via C# 4th Edition:

    Primary Constraints

    A type parameter can specify zero primary constraints or one primary constraint. A primary constraint can be a reference type that identifies a class that is not sealed. You cannot specify one of the following special reference types: System.Object, System.Array, System.Delegate, System.MulticastDelegate, System.ValueType, System.Enum, or System.Void. When specifying a reference type constraint, you are promising the compiler that a specified type argument will either be of the same type or of a type derived from the constraint type.

提交回复
热议问题