Anything you put inside a if(aqui)
will be transformed into true
or false
. The body of if
only executes if the result is true
.
Let’s simplify your example by keeping the result of Equals
in a variable:
bool resultado = periodoAnterior.Equals(dataReader["NOMEPERIODO"].ToString());
The variable resultado
contains true
or false
. So we have two options for the if
:
if (!(true)) {}
if (!(false)) {}
What is the exclamation !
does is invert the value of a boolean: !true
(read "not true") is false
, and !false
is true
. Therefore, the possible results for the if
evening:
if(false) {} // aqui o corpo nunca executa
if(true) {} // aqui o corpo executa
Thus, in its code, the body of if
only executes if the result of periodoAnterior.Equals(dataReader["NOMEPERIODO"].ToString())
for false
.
Note: Your doubt as to Equals
would deserve a separate question, but probably who wrote it led to C# a Java addiction. More details and exceptions in https://stackoverflow.com/questions/1659097/c-string-equals-vs
In this case then if periodAnterior.Equals(dataReader["PERIODNAME"]. Tostring())) is false, using the negation "becomes" true?
– Joao Paulo
@Joaopaulo Exatamente.
– Beterraba
Ah, cool, the issue now exclaimed me well.
– Joao Paulo
Mark friend’s answer as the solution to your problem if not the question remains open.
– Gustavuu
It takes a while to release acceptance. Done.
– Joao Paulo