Lou*_*hys 1 .net c# string null constructor
我有两个构造函数
MyObj(String s){ //first constructor
...
if(s==null) s = somecode;
this.s = s;
...
}
MyObj(): this(null) { } //second constructor
Run Code Online (Sandbox Code Playgroud)
这样,如果调用空构造函数,它将重定向到第一个构造函数并初始化由某些代码确定的值.
但是,现在我有了第三个构造函数
MyObj(Stream st){ //third constructor
...
}
Run Code Online (Sandbox Code Playgroud)
现在第二个构造函数不知道是应该调用第一个构造函数还是第三个构造函数.如何告诉它调用第一个构造函数?我试过MyObj(): this(String s = null),它也不起作用.
| 归档时间: |
|
| 查看次数: |
934 次 |
| 最近记录: |