I have a subclass which overrides a method in the base class. The base class's method has default parameters. My subclass is required to show those default parameters, although they need not be optionalized, in the overridden method.
public class BaseClass
{
protected virtual void MyMethod(int parameter = 1)
{
Console.WriteLine(parameter);
}
}
public class SubClass : BaseClass
{
//Compiler error on MyMethod, saying that no suitable method is found to override
protected override void MyMethod()
{
base.MyMethod();
}
}
However, if I change my method signature to
protected override void MyMethod(int parameter = 1)
or even
protected override void MyMethod(int parameter)
then it is happy. I would expect it to accept a parameterless method signature, and then for it to be allowed to use the default parameter when base.MyMethod() is called.
Why does the subclass's method require a parameter?