Boolean comparision problem when using boxed types.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

_value and valDoublet are both from type object. I think no one will expect
this behavior. ;-)

Console.WriteLine(string.Format("{0} == {1} = {2}", _value, valDoublet,
(bool) _value == (bool) valDoublet));
Console.WriteLine(string.Format("{0} == {1} = {2}", _value, valDoublet,
_value == valDoublet));

False == False = True
False == False = False
 
Georg,
_value and valDoublet are both from type object. I think no one will expect
this behavior. ;-)

Why not? == on object variables compares references (like
Object.ReferenceEquals), not values.



Mattias
 
Thank you.. I know.

but the boxing feature is a bit misleading in this case. further the visual
studio id returns true also for the 2nd code line (Immediate window).
 
Back
Top