C# (Sharp) Programming Language Question:

Download Job Interview Questions and Answers PDF

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

C# (Sharp) Programming Language Interview Question
C# (Sharp) Programming Language Interview Question

Answer:

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() {}
}

Download C# (Sharp) Programming Language Interview Questions And Answers PDF

Previous QuestionNext Question
Why are there five tracing levels in System.Diagnostics.TraceSwitcher?Why do I get a "CS5001: does not have an entry point defined" error when compiling?