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
| CSharp-Online.NET:FAQs |
| edit |
[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() {} }
[edit]
See also
- Are C# constructors inherited?
- How can one constructor call another?
- Are constructors the same in C++ and C#?
- Are destructors the same in C++ and C#?
- How call a virtual method from a constructor or destructor?
- How do destructors work in C#?
- How enforce constructor correctness in C#?
- How make a C# destructor virtual?
- What are the differences between C# and Java constructors?
- What are the differences between C# finalizers and Java destructors?
- What is the syntax for calling an overloaded constructor from within a constructor?
- Why must
structconstructors have at least one argument?