Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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()
{
}
}
}