Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0080

Constraints are not allowed on non-generic declarations

The syntax found may only be used in a generic declaration to apply constraints to the type parameter. For more information, see Generics (C# Programming Guide).

The following sample generates CS0080 because MyClass is not a generic class and MyMethod is not a generic method.

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 MyMethod() where MyMethod : new() // CS0080
        //the following line shows an example of correct syntax
        //public void MyMethod<U>() where U : struct
        {
        }
    }

    public class Program
    {
        public static void Main()
        {
        }
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft