編譯器錯誤 CS0080
非泛型宣告中不可使用條件約束
找到的語法只能用於泛型宣告中,以將條件約束套用至類型參數。 如需詳細資訊,請參閱泛型。
下列範例會產生 CS0080,因為 MyClass 不是泛型類別,而且 Foo 不是泛型方法。
namespace MyNamespace
{
public class MyClass where MyClass : System.IDisposable // CS0080 //the following line shows an example of correct syntax
//public class MyClass<T> where T : System.IDisposable
{
public void Foo() where Foo : new() // CS0080
//the following line shows an example of correct syntax
//public void Foo<U>() where U : struct
{
}
}
public class Program
{
public static void Main()
{
}
}
}