473,320 Members | 1,914 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,320 software developers and data experts.

Confused about line of code in book

I am reading a book that contains one line of code that I don't understand.
The line of code is supposed to be a constructor and is this:

protected NameValueList(SerializationInfo info, StreamingContext context) :
base(info, context)
{
}

This constructor is supposed to be necessary because the class inherits from
a class that implements ISerializable. The primary thing that I would like
to understand is the

: base(info, context)

part, what is the ":" doing there, is that some kind of inheritance or what?

Thank you.
Nov 16 '05 #1
4 1082
Rene wrote:
I am reading a book that contains one line of code that I don't understand.
The line of code is supposed to be a constructor and is this:

protected NameValueList(SerializationInfo info, StreamingContext context) :
base(info, context)
{
}

This constructor is supposed to be necessary because the class inherits
from a class that implements ISerializable. The primary thing that I would
like to understand is the

: base(info, context)

part, what is the ":" doing there, is that some kind of inheritance or what?


No, that's the delimiter for the call to the base class' constructor. So a
shortcut to avoid having to call the base class' constructor from the
constructor's body.

Frans.
--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #2
> No, that's the delimiter for the call to the base class' constructor. So a
shortcut to avoid having to call the base class' constructor from the
constructor's body.


Just out of curiosity, how would you call the base constructor from the
constructor's body? I tried the following and it did not work:

protected NameValueList(SerializationInfo info, StreamingContext context)
{
base(info, context)
}

Also if you have a minute, would you be so kind as to give me one or two
other examples on how to use this shortcut in other scenarios?

Thank you.
Nov 16 '05 #3
Rene wrote:
No, that's the delimiter for the call to the base class' constructor. So a
shortcut to avoid having to call the base class' constructor from the
constructor's body.
Just out of curiosity, how would you call the base constructor from the
constructor's body? I tried the following and it did not work:

protected NameValueList(SerializationInfo info, StreamingContext context)
{
base(info, context)
}


I formulated my sentence a bit ambiguistic, I'm sorry: I meant: the shortcut
/ construct is there to avoid having the developer to call the base class'
constructor from the constructor's body. This has an advantage: you know
where the call to the base class constructor is stated and that it is done at
the right moment: BEFORE the constructor of the derived class is executed.
Having a construct like in VB.NET, where you have to do MyBase.New() can lead
to errors if you expect some base class setup in your derived class but it
isn't there yet as the base class' constructor isn't called yet.
Also if you have a minute, would you be so kind as to give me one or two
other examples on how to use this shortcut in other scenarios?


If you have various overloads of the constructor, it is important to call
the right base class' constructor from the derived class constructors. In
these situations it is used. With classes which have constructors without
parameters, you don't need the construct as it is added for you if you don't
specify it.
Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #4
Thanks. I think I got it.

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@msnews.microsoft.com...
Rene wrote:
> No, that's the delimiter for the call to the base class' constructor.
> So a
> shortcut to avoid having to call the base class' constructor from the
> constructor's body.


Just out of curiosity, how would you call the base constructor from the
constructor's body? I tried the following and it did not work:

protected NameValueList(SerializationInfo info, StreamingContext context)
{
base(info, context)
}


I formulated my sentence a bit ambiguistic, I'm sorry: I meant: the
shortcut
/ construct is there to avoid having the developer to call the base class'
constructor from the constructor's body. This has an advantage: you know
where the call to the base class constructor is stated and that it is done
at
the right moment: BEFORE the constructor of the derived class is executed.
Having a construct like in VB.NET, where you have to do MyBase.New() can
lead
to errors if you expect some base class setup in your derived class but it
isn't there yet as the base class' constructor isn't called yet.
Also if you have a minute, would you be so kind as to give me one or two
other examples on how to use this shortcut in other scenarios?


If you have various overloads of the constructor, it is important to call
the right base class' constructor from the derived class constructors. In
these situations it is used. With classes which have constructors without
parameters, you don't need the construct as it is added for you if you
don't
specify it.
Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP

Nov 16 '05 #5

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

Similar topics

3
by: Suzette | last post by:
I'm going through Dan Appleman's book on API and am getting so confused. Can anyone suggest additional resources that might help me get the fog in my brain cleared? Thanks Sue
12
by: Blaze | last post by:
I am doing the first walk through on the Visual Studio .Net walkthrough book to learn a little about programming. I am having issues with the first tutorial not running correctly. It seems that...
3
by: Larry Tate | last post by:
I have had a monstrous time getting any good debugging info out of the .net platform. Using ... ..NET Framework 1.1 Windows 2K Server VB.NET <- is this the problem? error handling in the...
10
by: Xiaoshen Li | last post by:
Dear All, I am confused with prototypes in C. I saw the following code in a C book: void init_array_1(int data) { /* some code here */ }
3
by: NotGiven | last post by:
I see nothing on the mysql.com site abnout certificaiton for version 5.0 yet there's a book for it...
36
by: utab | last post by:
Dear, I have experince in C( numerical projects, like engineering problems, scientific applications) I have the basic notion of C++ also, I have read Accelerated C++ until Chapter 7, however it...
7
by: eric | last post by:
hello i'm confused by an example in the book "Effective C++ Third Edition" and would be grateful for some help. here's the code: class Person { public: Person(); virtual ~Person(); // see...
15
by: rEvolution27 | last post by:
I'm a c++ newbie here, trying out some stuff and when I try to compile this: void create() { char name; cout << "Creating a new timetable /n Please type a name for this timetable"; cin >name;...
6
by: ryanbayona | last post by:
I really wanted to learn C++ thats why i took the initiative to self- study. I am currently following the tutorial at this site: http://www.cprogramming.com/tutorial.html#c++tutorial but im...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.