Interview Questions

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

C# Interview Questions and Answers


(Continued from previous question...)

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

67. Why do I get a "CS5001: does not have an entry point defined" error when compiling?

The most common problem is that you used a lowercase 'm' when defining the Main method. The correct way to implement the entry point is as follows:
class test
{
static void Main(string[] args) {}
}

(Continued on next question...)

Other Interview Questions