这个条件是什么意思?
if (!helper?.Settings.HasConfig ?? false)
附言
helper
是一些class
的变量
Settings
是一些字段HasConfig
也是字段
最佳答案
嗯,?.
是一个空条件运算符
https://msdn.microsoft.com/en-us/library/dn986595.aspx
x?.y
表示如果 x
为 null 则返回 null
否则返回 x.y
??
是一个空合并运算符
https://msdn.microsoft.com/en-us/library/ms173224.aspx
x ?? y
表示如果 x == null
返回 y
,否则 x
结合以上所有内容
helper?.Settings.HasConfig ?? false
表示:如果
返回false
helper == null or
helper.Settings.HasConfig == null
否则返回
helper.Settings.HasConfig
没有??
和?.
的代码 if
可以改写成笨重
if (!(helper == null
? false
: (helper.Settings.HasConfig == null
? false
: helper.Settings.HasConfig)))
关于c# - C# 中变量后的 "?"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37851873/