Override destructor
In this chapter you will learn:
Call Base destructor
In the following example a base class is defined first. And the base class has a destructor. Then a derived class is created and extending the base class. In the derived class there is also a destructor. From the result we can see that the child destructor calls the base destructor automatically.
using System;/*jav a 2s .com*/
public class Base
{
~Base()
{
Console.WriteLine( "Base.~Base()" );
}
}
public class Derived : Base
{
~Derived()
{
Console.WriteLine( "Derived.~Derived()" );
}
}
public class MainClass
{
static void Main()
{
Derived derived = new Derived();
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Class