Even more fun with virtual methods
OK, after the last post I expect many people will nail this, so why don’t you show it your friends that don’t read my blog and see if they pass ;-)
Create a new instance of Derived, drop the reference, wait for the GC to collect it, and for any finalizers to run. What is the output?
And of course, the important question: why?
public class Base
{
public virtual void DoCleanUp() {
Console.WriteLine("Do Base's Cleanup");
}
~Base()
{
DoCleanUp();
}
}
public class Derived: Base
{
public override void DoCleanUp()
{
Console.WriteLine("Do Derived Cleanup");
}
~Derived()
{
DoCleanUp();
}
}