implicit called base() or this()

R

Ryan Liu

Hi,

When I extend a class, for the new class's parameter-less constructor, is
the :base() called implicitly?

And for overloaded constructor, is :this(), and in turn :base() always
implicitly called?

Thanks!
Ryan
 
F

Frans Bouma [C# MVP]

Ryan said:
Hi,

When I extend a class, for the new class's parameter-less
constructor, is the :base() called implicitly?
yes


And for overloaded constructor, is :this(), and in turn :base() always
implicitly called?

:this() isn't called, :base() is. If you want to call one overload of
the ctor from another, you've to specify :this(..) explicitly.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
B

Barry Kelly

Ryan Liu said:
When I extend a class, for the new class's parameter-less constructor, is
the :base() called implicitly?
Yes.

And for overloaded constructor, is :this(), and in turn :base() always
implicitly called?

this() is not called, but base() is called, unless you explicitly call a
different base or this constructor.

You can test these yourself with a little Console.WriteLine and a couple
of test classes. That's the best way to find the answer to these kinds
of questions.

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top