Question:
What is the difference between a.Equals(b) and a == b?
Answer:
a=b is used for assigning the values (rather then comparison) and a==b is for comparison.
Or a == b is used to compare the references of two objects a.Equals(b) is used to compare two objects Or
a equals b -> copies contents of b to a a == b -> checks if a is equal to b Source: CoolInterview.com
a==b is same as the symbol = used in mathematics Source: CoolInterview.com
Answered by: R.Karunakaran | Date: 11/29/2009
| Contact R.Karunakaran
a.Equals(b) handles NULL values
a==b does not handle NULL values.It will throw NULL Reference Exception. Source: CoolInterview.com
Answered by: Abhijeet N. Pawar | Date: 1/21/2010
| Contact Abhijeet N. Pawar
a==b used to compare the reference of the object
a.equals(b) used to compare the values For string comparison a.equals(b) is prefered Source: CoolInterview.com
Answered by: esakkirajak | Date: 2/25/2010
| Contact esakkirajak
equal is best b'coz it contain 1 byte memory rather than compare(==)which cover 4 byte memory Source: CoolInterview.com
Answered by: rajni | Date: 3/31/2010
| Contact rajni
a==b is used to compare the references of two objects a.equals(b)is used to compare twoobjects Source: CoolInterview.com
Answered by: jajala venkatamuni | Date: 4/9/2010
| Contact jajala venkatamuni
a==b is to compare the references of two objects. a.equals(b) is used to compare the objects (value of fields within the objects).
ie., If a and b are the objects of a class named class1 which is having two Fields Name and Age, the a.equals(b) will compare the values Name and Age fields value of this two objects. Source: CoolInterview.com
Answered by: Kannan | Date: 4/14/2010
| Contact Kannan
a==b is used to compare the references of two objects a.equals(b)is used to compare twoobjects Source: CoolInterview.com
Answered by: Rohit SIngh | Date: 6/28/2010
| Contact Rohit SIngh
a=b->is for assigning values a==b->is for comparing Source: CoolInterview.com
Answered by: Nagendran | Date: 7/20/2010
| Contact Nagendran
a==b can be used for all datatypes where as a.Equals(b) can be used to string .
a==b will produce null reference Exception if either of values is Null a.Equals(b) will not produce any Exception Source: CoolInterview.com
Answered by: Arif | Date: 8/6/2010
| Contact Arif
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|