How to simplify multiple constructors?
问题 I would like to have two constructors for a class, as follows: public MyClass() { // do stuff here } public MyClass(int num) { MyClass(); // do other stuff here } Is the above the correct way to achieve my purpose? Is there some kind of shorthand which is better? 回答1: public MyClass() { // do stuff } public MyClass(int num) : this () { // do other stuff with num } The : this() bit is called a Constructor Initialiser . Every constructor in C# has a an initialiser which runs before the body of