When would I need to call base() in C#?

Posted by user310291 on Stack Overflow See other posts from Stack Overflow or by user310291
Published on 2014-06-11T15:13:25Z Indexed on 2014/06/11 15:24 UTC
Read the original article Hit count: 105

Filed under:
|
|

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).

© Stack Overflow or respective owner

Related posts about c#

Related posts about inheritance