Solved

object values appearing the same arent equal

Posted on 2008-06-16
3
204 Views
Last Modified: 2010-04-15
Hi:

  In the debugger I can see that the values of two objects look the same but when I do o1 == o2 this doesnt seem to hold true. I am tearing my hair out. Any clue why this would be the case. The

DataRow[] r = datatable.Select("ROWKEY=" + x);
Object o1 = r[0][columnName];                                     // original value
Object o2 = db2cmd.Parameter[columnName].Value;  //new value

if (o1 == o2)
{

}
 

0
Comment
Question by:LuckyLucks
3 Comments
 
LVL 21

Expert Comment

by:naspinski
ID: 21799267
do something like this to see if you can get more one what those objects are:
Response.Write("o1: " + o1.ToString() + "<br />");

Response.Write("o2: " + o2.ToString() + "<br />");

Response.Write("o1 GetType: " + o1.GetType().ToString() + "<br />");

Response.Write("o2 GetType: " + o2.GetType().ToString() + "<br />");

Open in new window

0
 
LVL 10

Accepted Solution

by:
margajet24 earned 500 total points
ID: 21799305
try :

o1.Equals(o2)

since objects are refence type, they can have same values but their memory location is different..

check their value not their reference..
0
 

Author Comment

by:LuckyLucks
ID: 21813614
I am curious about the explanation. If o1 == o2 compares the mem location then they should never be equal during the run of the program. But in some cases they are. Can you explain this?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now