When would I need to call base() in C#?
- by user310291
My BaseClass Constructor is called whereas I have a constructor in derived class so when would I need to call base() ?
class BaseClass
{
public BaseClass() {
Debug.Print("BaseClass");
}
}
class InheritedClass : BaseClass
{
public InheritedClass()
{
Debug.Print("InheritedClass");
}
}
private void Form1_Load(object sender, EventArgs e)
{
InheritedClass inheritedClass = new InheritedClass();
}
Output
'Inheritance.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'
'Inheritance.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
BaseClass
InheritedClass
The thread 'vshost.RunParkingWindow' (0x12b4) has exited with code 0 (0x0).
The thread '<No Name>' (0x85c) has exited with code 0 (0x0).
The program '[4368] Inheritance.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[4368] Inheritance.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).