Can I call an overloaded constructor from another constructor of the same class in C#?

前端 未结 4 2031
走了就别回头了
走了就别回头了 2020-12-07 19:31

Can I call an overloaded constructor from another constructor of the same class in C#?

4条回答
  •  孤城傲影
    2020-12-07 20:11

    No, You can't do that, the only place you can call the constructor from another constructor in C# is immediately after ":" after the constructor. for example

    class foo
    {
        public foo(){}
        public foo(string s ) { }
        public foo (string s1, string s2) : this(s1) {....}
    
    }
    

提交回复
热议问题