Compiler Error CS0460
Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
When a generic method that is part of a derived class overrides a method in the base class, you may not specify constraints on the overridden method. The override method in the derived class inherits its constraints from the method in the base class.
The following sample generates CS0460.
// CS0460.cs
// compile with: /target:library
class BaseClass
{
BaseClass() { }
}
interface I
{
void F1<T>() where T : BaseClass;
void F2<T>() where T : struct;
void F3<T>() where T : BaseClass;
}
class ExpImpl : I
{
void I.F1<T>() where T : BaseClass {} // CS0460
void I.F2<T>() where T : class {} // CS0460
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: