共用方式為


編譯器錯誤 CS0450

更新:2007 年 11 月

錯誤訊息

'Type Parameter Name': 不能指定了條件約束類別,又同時指定 'class' 或 'struct' 條件約束

由於 struct 和 class 為互斥 (Mutually Exclusive) 類別,如果型別參數受限於 struct 型別條件約束 (Constraint),又受限於特定類別 (Class) 型別,就會產生邏輯上的矛盾。如果型別參數受限於特定類別的型別條件約束,則依照定義會受限於類別的型別條件約束,因此指定類別的型別條件約束是多餘的。

範例

// CS0450.cs
// compile with: /t:library
public class GenericsErrors 
{
    public class B { }
    public class G3<T> where T : struct, B { } // CS0450
// To resolve, use the following line instead:
// public class G3<T> where T : B { }
}