gpt4 book ai didi

c# - 如何创建空字符串?

转载 作者:太空宇宙 更新时间:2023-11-03 17:28:20 29 4
gpt4 key购买 nike

我有两个构造函数

MyObj(String s){ //first constructor
...
if(s==null) s = somecode;
this.s = s;
...
}

MyObj(): this(null) { } //second constructor

这样,如果调用空构造函数,它将重定向到第一个构造函数并初始化由某些代码确定的值。

但是,现在我有了第三个构造函数

MyObj(Stream st){ //third constructor
...
}

现在第二个构造函数不知道它应该调用第一个还是第三个构造函数。我如何告诉它调用第一个构造函数?我尝试了 MyObj(): this(String s = null) 但它也不起作用。

最佳答案

也许:MyObj(): this((string) null) {}

关于c# - 如何创建空字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3498956/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com