如何使用“??”编写单行“if”
示例:如何使用“??”编写以下内容而不是“?:”
SiteSettings = (sitessettings == null)
? UnityManager.Instance.Resolve<ISiteSettingsFactory>().Get(100)
: sitessettings;
答案 0 :(得分:5)
您的条件陈述相当于:
SiteSettings = sitessettings
?? UnityManager.Instance.Resolve<ISiteSettingsFactory>().Get(100);
答案 1 :(得分:4)
也许
SiteSettings = sitessettings ?? UnityManager.Instance.Resolve<ISiteSettingsFactory>().Get(100)
答案 2 :(得分:3)
试试这个?
SiteSettings = sitessettings ?? UnityManager.Instance.Resolve<ISiteSettingsFactory>().Get(100)
答案 3 :(得分:3)
SiteSettings = sitessettings ?? UnityManager.Instance.Resolve<ISiteSettingsFactory>().Get(100);