Das wird auch base-Konstruktor genannt. Wird der base-Konstruktor aufgerufen, dann wird zuerst dessen Code ausgeführt und dann erst der Code des abgeleiteten Konstruktors. Ein Beispiel zum Verständnis:
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
new BaseClass("Called by initialisation of BaseClass");
new DerivedClass("Called by initialisation of DerivedClass");
Thread.Sleep(10000); // wenn dieser Code in einem 'Console Application'-Projekt drin ist, dann kann man sich so den Output 10 Sekunden lang anschauen.
}
}
class BaseClass
{
public BaseClass(string value)
{
Console.WriteLine("Constructor of base class. " + value);
}
}
class DerivedClass : BaseClass
{
public DerivedClass(string value) : base(value)
{
Console.WriteLine("Constructor of derived class. " + value);
}
}
In der Konsole wird ausgegeben:
Constructor of base class. Called by initialisation of BaseClass
Constructor of base class. Called by initialisation of DerivedClass
Constructor of derived class. Called by initialisation of DerivedClass