object values appearing the same arent equal

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)
{

}
 

LuckyLucksAsked:
Who is Participating?
 
margajet24Connect With a Mentor IT Business AnalystCommented:
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
 
naspinskiCommented:
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
 
LuckyLucksAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.