[Solved] c#: (True==True) returning False [closed]


I can see two possibilities:

  • useaction.Postcondition[goalneeds] and current[goalneeds] return something other than a bool. They return an object of a class that has a ToString() method which sometimes returns the string "True". The specific objects returned in your case both generate "True" but are not the same object, so == is false (or the type of those objects overloads the == operator in such a way that it returns false, or some other object whose ToString() method returns "False").

    (Apparently this turned out to be the case, although the “class” is actually just object with a boxed bool inside. This does have the described effect because == performs reference equality in this case.)

  • The indexer of either useaction.Postcondition or current (or both) has a side-effect that alters its own value. As a result, the second invocation of it returns a different result than the first.

Both of these should be immediately visible in the debugger if you just stepped to the line of code you quoted and used the Watch window.

0

solved c#: (True==True) returning False [closed]