I implemented the following structure:
public abstract class A
{
protected A()
{
Test();
}
private void Test()
{
Console.WriteLine("2");
}
}
public class B : A
{
public B() : base()
{
Console.WriteLine("1");
}
}
When I create an instance of class B
, the method Test()
is executed before the constructor calls in class B
. In my case, this method should run after the child is fully initialized. A possible way to make it work would be to make Test()
accessible from B
and call it at the end of its constructor. That would work but if someone creates another subclass of A
, there is a chance that he forgets to call the method. My question is whether there is a more general solution in the base class to make sure that the method is executed after a child is fully initialized.