this() vs base()

  • Thread starter Thread starter Flip
  • Start date Start date
F

Flip

I'm reading in an article suggested by someone on one of the newsgroups here
(http://www.25hoursaday.com/CsharpVsJava.html) and under the topic titled
"Calling Base Class Constructors and Constructor Chaining" in the C#
example, they use the base() and this() constructors. Am I correct in
saying, the this() is the constructor chaining and the base() is like the
super() in java?

Thanks.
 
Flip,

Yes, you are right. However, the restriction in .NET is that the base
constructor must be called before any code is executed in the derived
class's constructor (I believe that super can be called anywhere in the
constructor in java).

Hope this helps.
 
this() is for constructor chaining as you say. base() is for stating how a base class constructor other than it's default constructor should be called - I have no idea whether this equates to super() in Java

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

I'm reading in an article suggested by someone on one of the newsgroups here
(http://www.25hoursaday.com/CsharpVsJava.html) and under the topic titled
"Calling Base Class Constructors and Constructor Chaining" in the C#
example, they use the base() and this() constructors. Am I correct in
saying, the this() is the constructor chaining and the base() is like the
super() in java?

Thanks.



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004



[microsoft.public.dotnet.languages.csharp]
 
Nicholas Paldino said:
Yes, you are right. However, the restriction in .NET is that the base
constructor must be called before any code is executed in the derived
class's constructor (I believe that super can be called anywhere in the
constructor in java).

Nope, the rules are very similar in Java - super() or this() has to be
the first statement in a constructor.
 

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

Back
Top