Hi
Having difficulty getting myself clear on how a type's operator== fits
in with Object.Equals.
Let's just consider reference types.
The default operator== tests for object identity (reference)
equivalence. You can override it if you like.
Object has ... public virtual bool Equals(object);
The default implementation also gives you a reference equality test.
You can override it if you like.
So ... why two different ways of achieving the same thing? What's one
for? What's the other for? When would you override one? When would you
override the other? I'm asking how these two methods are the same and
also how they are different!!! Let's just consider reference types
only.
I did notice if you implement IComparable you must provide an
implementation of Equals.
I also noticed this advice (Object.Equals help): "if your programming
language supports operator overloading and if you choose to overload
the equality operator for a given type, that type should override the
Equals method. Such implementations of the Equals method should return
the same results as the equality operator."
If they need to be consistent why *two* different ways to achieve the
same functionality - isn't this asking for trouble?!
And then it says this seemingly contradictory quote: "most reference
types should not overload the equality operator, even if they override
Equals."
Eek - it's pretty clear now that I need some help from someone
understanding the rationale behind == and .Equals!!!
As a finale, what's the point of the static Equals method on Object?
public static bool Equals(object objA, object objB);
What does it do that objA.Equals(objB) would not achieve?
Cheers for listening and hope someone can help my lack of
understanding!
Emma Middlebrook
em**************@fastmail.fm