Click here to Skip to main content
15,913,282 members
Home / Discussions / C#
   

C#

 
QuestionInheritance and constructors Pin
Dewald28-Aug-08 4:22
Dewald28-Aug-08 4:22 
Hi all, I'm having a hard time getting my head around this() and base(), hoping someone can help.

Let's say I have classB which inherits classA both have a constructor and an overloaded constructor.

class classA
{
   public classA()
   {
      //some code
   }
   public classA(int i)
   {
      //some code
   }
}

class classB
{
   public classB()
   {
      //some code
   }
   public classB(int i)
   {
      //some code
   }
}


How do I get the overloaded constructor of classB to first call the default constructor of classB and then the similar overloaded constructor of the base class, classA? I seem to be able to have it call either the default constructor of classB OR the overloaded constructor of classA by declaring the overloaded constructor of classB as
public classB(int i) : this()
or
public classB(int i) : base(i)

but how do I get it to call both?
AnswerRe: Inheritance and constructors Pin
netJP12L28-Aug-08 4:35
netJP12L28-Aug-08 4:35 
GeneralRe: Inheritance and constructors Pin
Dewald29-Aug-08 3:11
Dewald29-Aug-08 3:11 
AnswerRe: Inheritance and constructors Pin
Pete O'Hanlon28-Aug-08 4:36
mvePete O'Hanlon28-Aug-08 4:36 
GeneralRe: Inheritance and constructors Pin
N a v a n e e t h28-Aug-08 5:21
N a v a n e e t h28-Aug-08 5:21 
GeneralRe: Inheritance and constructors Pin
Dewald29-Aug-08 3:26
Dewald29-Aug-08 3:26 
AnswerRe: Inheritance and constructors Pin
Frank Horn28-Aug-08 4:39
Frank Horn28-Aug-08 4:39 
GeneralRe: Inheritance and constructors Pin
Dewald29-Aug-08 3:31
Dewald29-Aug-08 3:31 
AnswerRe: Inheritance and constructors Pin
laserbaronen28-Aug-08 4:42
laserbaronen28-Aug-08 4:42 
GeneralRe: Inheritance and constructors Pin
Dewald29-Aug-08 3:31
Dewald29-Aug-08 3:31 
Question[Message Deleted] Pin
hadad28-Aug-08 4:16
hadad28-Aug-08 4:16 
AnswerRe: BinnaryWriter Class Pin
led mike28-Aug-08 5:05
led mike28-Aug-08 5:05 
GeneralRe: BinnaryWriter Class Pin
Mark Salsbery28-Aug-08 6:29
Mark Salsbery28-Aug-08 6:29 
GeneralRe: BinnaryWriter Class Pin
led mike28-Aug-08 6:42
led mike28-Aug-08 6:42 
GeneralRe: BinnaryWriter Class Pin
lisan_al_ghaib28-Aug-08 22:10
lisan_al_ghaib28-Aug-08 22:10 
GeneralRe: BinnaryWriter Class Pin
Mark Salsbery29-Aug-08 5:18
Mark Salsbery29-Aug-08 5:18 
JokeRe: BinnaryWriter Class Pin
lisan_al_ghaib29-Aug-08 5:22
lisan_al_ghaib29-Aug-08 5:22 
GeneralRe: BinnaryWriter Class Pin
Pete O'Hanlon28-Aug-08 8:13
mvePete O'Hanlon28-Aug-08 8:13 
GeneralRe: BinnaryWriter Class Pin
led mike28-Aug-08 8:16
led mike28-Aug-08 8:16 
GeneralRe: BinnaryWriter Class Pin
Pete O'Hanlon28-Aug-08 8:42
mvePete O'Hanlon28-Aug-08 8:42 
GeneralRe: BinnaryWriter Class Pin
led mike28-Aug-08 8:52
led mike28-Aug-08 8:52 
Questioncopy and paste Pin
netJP12L28-Aug-08 4:16
netJP12L28-Aug-08 4:16 
QuestionReading more than column in a text file Pin
ianhunt0128-Aug-08 3:57
ianhunt0128-Aug-08 3:57 
QuestionTemp Folder Pin
hadad28-Aug-08 3:04
hadad28-Aug-08 3:04 
AnswerRe: Temp Folder Pin
DaveyM6928-Aug-08 3:11
professionalDaveyM6928-Aug-08 3:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.