473,408 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

this() vs base()

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.
Nov 16 '05 #1
4 7564
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Flip" <[remove]ph******@hotmail.com> wrote in message
news:OW**************@TK2MSFTNGP15.phx.gbl...
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.

Nov 16 '05 #2
Thanks again Nicholas! :>
Nov 16 '05 #3
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/<OW**************@TK2MSFTNGP15.phx.gbl>

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]
Nov 16 '05 #4
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dave | last post by:
class base { public: base(const base &other) { // Init. here... } // Stuff }; class derived: public base { public:
8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
2
by: Stephan Br?nnimann | last post by:
Dear all thanks to Scott Meyers (ME C++, item 33) we know assignment operators should be protected in the base class. Is there a common pattern (similar to virtual construction via `clone()')...
8
by: Andreas Lagemann | last post by:
Hi, after browsing FAQ and archive for a while I decided that the following is a legal question. Consider this: Class Base { public: Base() {}
5
by: Fernando Cacciola | last post by:
Hi people, I'm testing Microsoft Visual Studio 2005 Version 8.0.50727.42 (RTM.050727-4200) with our code base. I'm getting lots of errors on code that compiled fine in 7.1.
4
by: Jeff | last post by:
The derived class below passes a reference to an object in its own class to its base calss constructor. The code compiles and will run successfully as long as the base class constructor does not...
19
by: Robbie Hatley | last post by:
For your enjoyment, a function that expresses any integer with absolute value less-than-or-equal-to nine quintillion in any base from 2 to 36. (For larger bases, you could expand the "digit"...
5
by: Michael | last post by:
Hi, Could you tell me whether the following two statement are the same? Derived class is derived from Base class. 1. Base* ptr1; 2. Derived * ptr2; Does it mean ptr1 is the same as ptr2?
2
by: qazmlp1209 | last post by:
class base { public: base() { } base(int number) { priNumber = number ;
2
by: mike.lussier | last post by:
I have written some simple XSL pages to extract the data I need but each device here has a total of 6 keys and within this 6 values a time stamp and how long until the next data extraction ( 300...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.