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