Solved

object values appearing the same arent equal

Posted on 2008-06-16
3
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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