When I compare two variables typed as object
and both contain same value,
the comparison result using ==
operator produces false
.
object Var1 = "X";
object Var2 = "X";
// This produces false result
bool Match = Var1 == Var2;
Why is this happening?
Edit: Above is the code that actually works!
I have based it on my real code which looks like this and does not work:
ChoiceValue = Choice.GetValue(FieldTemplate.ValueDataType);
if (ChoiceValue == Field.Value) RadioButton.IsChecked = true;
ChoiceValue
is object
and also the Field.Value
is property typed as object
.
Obviously works differently in different situations.