C # here - is it possible for an abstract base class to define a method with default behavior and call this default value before implementing a child class? For instance:
public abstract class Base
{
public virtual int GetX(int arg)
{
if (arg < 0) return 0;
}
}
public class MyClass : Base
{
public override int GetX(int arg)
{
return arg * 2;
}
}
MyClass x = new MyClass();
Console.WriteLine(x.GetX(5));
Console.WriteLine(x.GetX(-3));
Basically, I donβt want the same template in every child implementation ...
source
share