Why can't I write Nullable>?

前端 未结 5 1161
陌清茗
陌清茗 2020-12-06 17:16

The definition of Nullable is:

[SerializableAttribute]
public struct Nullable where T : struct, new()

The constraint

5条回答
  •  猫巷女王i
    2020-12-06 17:54

    Because it's in the C# spec (section 4.4.4):

    If the constraint is the value type constraint (struct), the type A must satisfy one of the following:

    • A is a struct type or enum type, but not a nullable type. Note that System.ValueType and System.Enum are reference types that do not satisfy this constraint.
    • A is a type parameter having the value type constraint (§10.1.5).

提交回复
热议问题