编译器错误 CS0452

更新:2007 年 11 月

错误消息

类型“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