samedi 20 juillet 2019

Strange behavior when comparing int in IF statement

I am trying to compare two int variables in IF statement. In some cases it works well, but in some cases there's very strange behavior, at least to me. Basically I want to return true when two variables aren't equal.

In pseudocode:

if (!someMethodToRetrieveInt() == someStructure.intVariable)
    return true;
return false;

While debugging i was checking locals, and i am sure variable returned by method and member of structure were not equal, but code returned false anyway.

Are theese two same?

if (!someMethodToRetrieveInt() == someStructure.intVariable)
    return true;
return false;

if (someMethodToRetrieveInt() != someStructure.intVariable)
    return true;
return false;

Aucun commentaire:

Enregistrer un commentaire