faqts : Computers : Programming : Languages : C# : Language

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

24 of 29 people (83%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Does == use the Equals method?
Does != use the Equals method?

Apr 27th, 2002 19:38
Nathan Wallace,


Short answer - no.
Long answer:
Equals() is an overridable method for comparing whether two objects 
are equivalent. 
The rules for != and == are a little complex:
- if the two objects are value objects (like ints), then == is an 
equality test
- if the two objects are strings, then == is a (string value) equality 
test 
eg. the following code returns true
  string one = "test";
  string two = "test";
  one == two
- for any other kind of object, == is an identity test (ie. the 
objects being compared have the same object identifier).
!= is just the negation of ==.