简体   繁体   English

C OR条件运算符中的条件差异

[英]C# Conditioning Difference In OR Operator

What is the difference in both of the expressions ? 这两个表达式有什么区别? Using brackets or not in this case. 在这种情况下是否使用括号。 What is the difference ? 有什么区别 ?

(!String.IsNullOrEmpty(model.SpouseCitizenType) || !String.IsNullOrEmpty(model.SpouseNomPrenom)) &&
                 String.IsNullOrEmpty(model.SpouseEGN);

!String.IsNullOrEmpty(model.SpouseCitizenType) || !String.IsNullOrEmpty(model.SpouseNomPrenom) &&
                 String.IsNullOrEmpty(model.SpouseEGN);

Operator AND && has a higher precendence than OR || 运算符AND &&的优先级高于OR || . So, if we denote conditions used here as 1, 2 and 3, first line is equvalent to 因此,如果我们将此处使用的条件表示为1、2和3,则第一行等效于

(1 || 2) && 3

and the second 第二个

1 || (2 && 3)

For the full list of operators sorted in order of precedence check out this MSDN page 有关按优先级排序的运算符的完整列表,请查看此MSDN页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM