It’s much easier to solve this problem mathematically, simply by replacing your long variable names with type letters A
or B
, replacing the symbol &&
with a simple and
or AND
or e
, (and ignoring, for practical reasons, that "3" and "4" are strings). In your case we have:
cmbCdTipoProcesso.SelectedValue != "3" && cmbCdTipoProcesso.SelectedValue != "4"
How simply translated does that mean:
A != 3 e A != 4
That is to say:
A é diferente de 3 e A é diferente de 4
Suppose A
is 3.
Let’s take a look at the expression:
A é diferente de 3 e A é diferente de 4
The expression above will be valued false, because A = 3
, even though A != 4
.
If A
were 4, we would be in the same situation.
Only in the event that A
is different at the same time of 3 and 4 is that block of your if
will be executed.
In a more general case, where times A
and B
to be valued:
if A != 3 e B != 4
according to one of the laws of Morgan’s:
if !(A == 3 ou B == 4)
i.e., in Portuguese:
se não (A igual a 3 ou B igual a 4)
In other words, the if
will be executed when the situation in brackets is false (because the denial of false is true), or all cases in which A is different from 3 and B is different from 4 at the same time, for example:
A = 2 // A é diferente de 3
B = 7 // B é diferente de 4
If A equals to 3 or B equals to 4, or both, the expression of if
will not be considered true. I repeat, A
has to be different from 3 and B
it has to be different from 4, if not the block of the if
will not be executed.
Perfect Bigown, perfect. This will prove the guy wrong and I can work as is. The programmer before me is correct. There’s a lot of criticism of the guy and I didn’t come here for it, so I’m gonna prove the previous colleague was right.
– pnet
@pnet If they have time to criticize (erroneously) Boolean algebra and micro-manage code like that, I would say that the problem is management, not implementation.
– OnoSendai