implicit called base() or this()

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
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
 
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#)
------------------------------------------------------------------------
 
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
 
Back
Top