CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.faq_frequently_asked_questions Tags:
Item Type: NewsGroup Date Entered: 8/27/2007 4:36:55 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 3 Views: 113 Favorited: 0 Favorite
4 Items, 1 Pages 1 |< << Go >> >|
maulikk2000
Asp.Net User
what is the difference between == and .Equals8/27/2007 4:36:55 AM

0

Hi guys,

bool b = (object)1 == (object)1; //returns false; 

bool b1 = (object)"a" == (object)"a"; //returns true

bool b2 = ((object)1).Equals((object)(1)); //returns true

 

Could any one explain me why first and second statement has different output??

 

Thanks in advance,

Maulik

Sweeperq
Asp.Net User
Re: what is the difference between == and .Equals8/27/2007 4:49:31 AM

0

This article should help understand the differences:

http://blogs.msdn.com/csharpfaq/archive/2004/03/29/102224.aspx


When your question has been sufficiently answered, please be sure to mark your question as answered. Also, please share your solution if you had to figure it out on your own!
prowla2003
Asp.Net User
Re: what is the difference between == and .Equals8/27/2007 4:53:33 AM

0

 

int a = 5;
int b = 5;

object oa = a;
object ob = b;

When dealing with reference types  (ie objects) the == operator tells you if the objects are actually the same object which they are not

so (oa == ob) is false

Whereas in this instance oa.Equals(ob) is  true as it compares the value of the object.

 


the string object is a special case where == is the same as .Equals 

bool b1 = (object)"a" == (object)"a"; //returns true


 


Paul.

If you want Reflexology in Sydney then click on the link...

ofer.comfort
Asp.Net User
Re: what is the difference between == and .Equals8/27/2007 8:06:34 AM

0

String class operator == and method Equals are the same. In all other cases "==" compares object's address (must be the same object to be equal) and "Equal" object content

4 Items, 1 Pages 1 |< << Go >> >|


Free Download:




   
  Privacy | Contact Us
All Times Are GMT