PC Review


Reply
Thread Tools Rate Thread

Boolean comparision problem when using boxed types.

 
 
=?Utf-8?B?R2VvcmcgU2NobWlkdA==?=
Guest
Posts: n/a
 
      17th Jan 2005
_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
 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      17th Jan 2005
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
=?Utf-8?B?R2VvcmcgU2NobWlkdA==?=
Guest
Posts: n/a
 
      17th Jan 2005
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).

"Georg Schmidt" wrote:

> _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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BUG:Incorrect behavior of Boxed Value Types in MSDN Docs... AshokG Microsoft C# .NET 2 20th Aug 2007 07:38 AM
BUG:Incorrect behavior of Boxed Value Types in MSDN Docs... AshokG Microsoft VB .NET 2 20th Aug 2007 07:38 AM
Boxed Value Types =?Utf-8?B?RGFyZWs=?= Microsoft Dot NET Framework 2 24th Dec 2005 10:07 AM
Help: VS2003 BUG? - Boxed value types cannot be casted to custom value types Laura T. Microsoft C# .NET 3 15th Jul 2004 04:23 PM
== operator not working on boxed value types Kenneth Baltrinic Microsoft C# .NET 6 18th Nov 2003 02:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:29 AM.