I’m having a problem with (true==true) returning false.
Console.WriteLine(
useaction.Postcondition[goalneeds].ToString() + "==" +
current[goalneeds].ToString() + " returns " +
(useaction.Postcondition[goalneeds] == current[goalneeds]).ToString());
Output:True==True returns False
useaction.Postcondition is of the same type as current.
Despite what the preview color says, “Postcondition” is not static
Any help is appreciated, I don’t know any other relevant information I can share.
Solution:
bool a = (bool)useaction.Postcondition[goalneeds];
bool b = (bool)current[goalneeds];
Console.WriteLine(a.ToString() + "==" + b.ToString() + " returns " + (a==b).ToString());
The first code compared object types. The second code compared bools.
I can see two possibilities:
useaction.Postcondition[goalneeds]andcurrent[goalneeds]return something other than abool. They return an object of a class that has aToString()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 whoseToString()method returns"False").(Apparently this turned out to be the case, although the “class” is actually just
objectwith a boxedboolinside. This does have the described effect because==performs reference equality in this case.)The indexer of either
useaction.Postconditionorcurrent(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.