How to call another ctor?
For example, in my class Foo has two ctor methods, how do I call parameterless ctor in another ctor?
class Foo {
public Foo() {
// initialized this class
}
public Foo(int a, int b) {
// i开发者_StackOverflownitialized by Foo(), how do I call Foo() here ?
.... // other initializing here
}
}
Add : this()
between the parameter list and the opening brace:
class Foo {
public Foo() {
}
public Foo(int a, int b) : this() {
}
}
Put it in the initializer list, like so:
public Foo(int a, int b) : this() {
// initialized by Foo(), how do I call Foo() here ?
.... // other initializing here
}
精彩评论