类型“type name”必须是引用类型,才能用作泛型类型或方法“'identifier of generic”中的参数“parameter name”
当传递诸如 struct 或 int 的值类型作为具有引用类型约束的泛型类型或方法参数时,将发生此错误。
示例
以下代码生成错误 CS0452。
// CS0452.cs
using System;
public class BaseClass<S> where S : class { }
public class Derived1 : BaseClass<int> { } // CS0452
public class Derived2<S> : BaseClass<S> where S : struct { } // CS0452