Object.Equals (obj1, obj2) vs obj1.Equals (obj2)?

Assuming both objects are not value types, and both represent types that overrides the Equals (...) method, is there any functional difference between:

  • Call obj1.Equals(obj2)
  • Call Object.Equals(obj1, obj2) ... or are they functionally the same?

The Apress book I'm reading (Pro C # 2008), which is actually pretty good, refers to this method (as well as ReferenceEquals(...) ) as "(very useful) static methods," but I'm trying my best see benefits here.

For ReferenceEquals(...) I can see this utility, because it is still able to determine whether the same object is referencing two objects (regardless of whether the Equals(...) method and the == operator have been processed) .

For another ... not so much; Am I missing something here?

+4
source share
3 answers

Object.Equals (obj1, obj2):

if obj1 and obj2 are the same link, returns true

If obj1 or obj2 is null, return false

otherwise returns obj1.Equals (obj2)

+8
source

Imagine if in the first case obj1 was zero.

+8
source

All Articles