Ala*_*an2 1 c# int boolean type-conversion
我的代码看起来像这样:
if (Settings.adp == true)
App.DB.UpdateIntSetting(SET.Adp, 0);
else
App.DB.UpdateIntSetting(SET.Adp, 1);
Run Code Online (Sandbox Code Playgroud)
有没有办法通过以某种方式将bool Settings.adp转换为int(0或1)来将其降低到一行
Nat*_*rry 11
您可以使用三元运算符将其合并为一行:
App.DB.UpdateIntSetting(SET.Adp, Settings.adp ? 0 : 1);
Run Code Online (Sandbox Code Playgroud)
从文档中
条件?结果:替代方案