.NET – When using the default constructor instantiated class, do it also call the base class constructor?

Does anyone know what C# behaves? Are all .NET languages ​​the same?
Yes-if you do not explicitly call the base class constructor, it will be in any constructor in the derived class This happens.

class Base
{
Base(){}
Base(int i){}< br />}

class Derived: Base
{
Derived(bool x) {} // calls Base.Base()
}
< br />class Derived2: Base
{
Derived2(): base(10) {} // calls Base.Base(int)
}

Does anyone know what the behavior of C# is? Are all .NET languages ​​the same?

Yes-if you don’t explicitly call the base class constructor, this will happen in any constructor in the derived class.

class Base
{
Base(){}
Base(int i){}
}

class Derived: Base
{
Derived(bool x) {} // calls Base.Base()
}

class Derived2: Base
{
Derived2(): base(10) {} // calls Base.Base(int)
}

Leave a Comment

Your email address will not be published.