共用方式為


編譯器錯誤 CS0456

更新:2007 年 11 月

錯誤訊息

型別參數 'Type Parameter Name 1' 有 'struct' 條件約束,因此 'Type Parameter Name 1' 不能做為 'Type Parameter Name 2' 的條件約束

實值型別條件約束已隱含密封,所以這些條件約束不能當做其他型別參數的條件約束使用。這是因為實值型別無法覆寫。若要解決這個錯誤,請將實值型別條件約束直接放置在第二個型別參數上,而不要透過第一個型別參數間接放置。

範例

下列範例會產生 CS0456:

// CS0456.cs
// compile with: /target:library
public class GenericsErrors
{
   public class G5<T> where T : struct
   {
      public class N<U> where U : T {}   // CS0456
      public class N2<U> where U : struct {}   // OK
   }
}