例如,在我的班级中,Foo有两种ctor方法,如何在另一个ctor中调用无参数ctor?
class Foo {
public Foo() {
// initialized this class
}
public Foo(int a, int b) {
// initialized by Foo(), how do I call Foo() here ?
.... // other initializing here
}
}
答案 0 :(得分:5)
在参数列表和左大括号之间添加: this()
:
class Foo {
public Foo() {
}
public Foo(int a, int b) : this() {
}
}
答案 1 :(得分:0)
将它放在初始化列表中,如下所示:
public Foo(int a, int b) : this() {
// initialized by Foo(), how do I call Foo() here ?
.... // other initializing here
}