C# FAQ: What is the syntax for calling an overloaded constructor from within a constructor?

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

What is the syntax for calling an overloaded constructor from within a constructor?

You may have noticed that this() and constructor-name() do not compile.

The syntax for calling another constructor is as follows:

class A
{
   A (int i) { }
}
 
class B : A
{
   B() : base (10)    // call base constructor A(10)
      { }
 
   B(int i) : this()  // call B()
      { }
 
   public static void Main() {}
}


See also



Personal tools