What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?

The syntax for calling another constructor is as follows:

class B

{

B(int i)

{ }

}

class C : B

{

C() : base(5) // call base constructor B(5)

{ }

C(int i) : this() // call C()

{ }

public static void Main() {}

}

Showing Answers 1 - 5 of 5 Answers

Ans:

The syntax for calling another constructor is as follows:
class B
{
B(int i)
{ }
}
class C : B
{
C() : base(5) // call base constructor B(5)
{ }
C(int i) : this() // call C()
{ }
public static void Main() {}
}

Raj

  • Oct 19th, 2006
 

wrongit has have "{}" now after the call to the base class public c1() : base() { }(atleast in .net 2.0 )

  Was this answer useful?  Yes

zeroKelvin71493

  • Jun 18th, 2007
 

You need to make the constructors public ... then it will compile and run.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions