开发者

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
       }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜