编译器错误 CS0080
更新:2007 年 11 月
错误消息
在非泛型声明上不允许使用约束
找到的语法只能用于泛型声明才能对类型参数应用约束。有关更多信息,请参见泛型(C# 编程指南)。
下面的示例生成 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()
{
}
}
}