The overriding method cannot change the inherited constraints. : Generic Class Hierarchy « Generics « C# / C Sharp






The overriding method cannot change the inherited constraints.

 

using System;

public class MyClass {
    public virtual void MethodA<T>(T arg)
        where T : new() {
    }
}

public class YClass : MyClass {
    public override void MethodA<T>(T arg) {
        T obj = new T();
    }
}

 








Related examples in the same category

1.A simple generic class hierarchyA simple generic class hierarchy
2.A derived class with its own type parametersA derived class with its own type parameters
3.A non-generic class can be the base class of a generic derived classA non-generic class can be the base class of a generic derived class
4.Overriding a virtual method in a generic classOverriding a virtual method in a generic class