Reputation: 354
This is weird. I have this C# code:
bool value = (((Literal)expr.left).value == ((Literal)expr.right).value);
When I inspect it with the Xamarin debugger, it tells me value
is false
, but (((Literal)expr.left).value == ((Literal)expr.right).value)
is true
. Why is that? I'm so confused...
Upvotes: 0
Views: 85
Reputation: 354
Found it. ((Literal)expr.left).value
is an object
, which means this always will return false unless right and left are the same bool, which they're not.
Casting them both to bool will compare their value instead.
bool value = ((bool)((Literal)expr.left).value == (bool)((Literal)expr.right).value);
Upvotes: 4