471,627 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Calling Base Class' Ctor

BDB
Hi,

I'm trying to call a base class' constructor. This is giving me an error:
Use of keyword 'base' is not valid in this context.

....

public class B : A
{
B( int i )
{
base( i ) //Calling A's ctor of same declaration
}
}
Thanks,
Bryan
Feb 16 '06 #1
3 2505
You have to call it before the function body, like so:
public class B : A
{
B( int i ) : base( i )
{
}
}

Good luck,
Jared

Feb 16 '06 #2
BDB

"BDB" <bd*@reply.to.group.com> wrote in message
news:Ou**************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm trying to call a base class' constructor. This is giving me an error:
Use of keyword 'base' is not valid in this context.

...

public class B : A
{
B( int i )
{
base( i ) //Calling A's ctor of same declaration
}
}
Thanks,
Bryan


Found it.

public class B : A
{
B( int i ) : base( i ) {}
}
Feb 16 '06 #3
BDB <bd*@reply.to.group.com> wrote:
I'm trying to call a base class' constructor. This is giving me an error:
Use of keyword 'base' is not valid in this context.

...

public class B : A
{
B( int i )
{
base( i ) //Calling A's ctor of same declaration
}
}


I see you've found the answer to this one - but if you have any other
questions about constructors, see
http://www.pobox.com/~skeet/csharp/constructors.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Douglas Peterson | last post: by
27 posts views Thread by tuvok | last post: by
6 posts views Thread by Justin | last post: by
7 posts views Thread by Jo Vermeulen | last post: by
8 posts views Thread by Alex Vinokur | last post: by
8 posts views Thread by Mike - EMAIL IGNORED | last post: by
4 posts views Thread by Fedor Semenov | last post: by
3 posts views Thread by hurcan solter | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.