解决方法
这绝对是一个好习惯,主要有两个原因:
避免代码重复
class Foo { public Foo(String myString,Int32 myInt){ //Some Initialization stuff here } //Default value for myInt public Foo(String myString) : this(myString,42){} //Default value for both public Foo() : this("The Answer",42){} }
强制执行良好的封装
public abstract class Foo { protected Foo(String someString) { //Important Stuff Here } } public class Bar : Foo { public Bar(String someString,Int32 myInt): base(someString) { //Let's the base class do it's thing // while extending behavior } }