gpt4 book ai didi

c# - 我有一个返回字符串的方法,但是变量的类型为 nullable boolean

转载 作者:行者123 更新时间:2023-11-30 21:49:17 26 4
gpt4 key购买 nike

我在以下方面遇到构建错误:

protected override string SHow()
{
return _type ? "Y" : "N";
}

_type 是可为空的 bool 类型。我得到“无法从 ?bool 转换为 bool。

请问能帮忙解决吗?

最佳答案

可空类型使用 Value 属性提供对其基础值的访问。

返回 _type.HasValue && _type.Value ? "Y": "N";

好的,编辑以返回 null...

const string trueValue = "True";
const string falseValue = "False";

return _type.HasValue ? (_type.Value ? trueValue : falseValue) : null;

关于c# - 我有一个返回字符串的方法,但是变量的类型为 nullable boolean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37106762/

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