布尔逻辑问题:我可以将这4个if语句强制转换为单个布尔语句吗?

Gav*_*vin 0 c# boolean-logic

我有一个布尔逻辑问题.我有以下if语句应该能够合并为一个布尔表达式.请帮忙.我花了太多时间在这上面,我实在太羞于问我的同事.

if (denyAll == true & allowOne == false) return false;
if (denyAll == true & allowOne == true) return true;
if (denyAll == false & allowOne == false) return false;
if (denyAll == false & allowOne == true) return true;
return true; //should never get here
Run Code Online (Sandbox Code Playgroud)

我确信有一个优雅的解决方案.

谢谢

Hug*_*ugh 9

return allowOne;做的伎俩?


Joh*_*hnD 5

我认为这只是:

return allowOne;
Run Code Online (Sandbox Code Playgroud)

denyAll值似乎并不重要:

denyAll   allowOne   result
false     false      false
false     true       true
true      false      false
true      true       true
Run Code Online (Sandbox Code Playgroud)