类型“Type Name”必须是不可以为 null 值的类型,才能将其用作泛型类型或方法“Generic Identifier”中的参数“Parameter Name”
如果在对其上具有 value 约束的泛型类型或方法进行实例化时使用了一个非值类型的参数,则会出现此错误。 当你使用可以为 null 的值类型参数时,它也会发生。 请参阅以下示例中的最后两行代码。
示例
以下代码生成此错误。
// CS0453.cs
using System;
public class HV<S> where S : struct { }
// CS0453: string is not a value type
public class H1 : HV<string> { }
// CS0453: H1 is a class, not a struct
public class H2 : HV<H1> { }
// CS0453: HV is based on a class, not a struct
public class H3<S> : HV<S> where S : class { }
public class H4<S> : HV<S> where S : struct { } // OK
// CS0453: HV accepts a nullable int type
public class H4 : HV<int?> { }
// CS0453: HV is based on Nullable type of int
public class H5 : HV<Nullable<Nullable<int>>> { }