共用方式為


編譯器錯誤 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