Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. COninj, I'm not sure I get you, checking that the other object's type isn't sufficient - what if Equals(A obj) is called on type B? - perfectly possible when for example you have a List<A> since the collection can contain both A and subtype B. And, since you haven't sealed A you can't know what would make sense for Equals(A obj) when called on any subtype (incl. B). You're going to be forced to provide a virtual member so that subtypes can override behavior as appropriate. An alternative might be for Equals(A object) to check this.GetType() == typeof(A) and throw an exception if false. YUCK!
      singulars
    2. COIMO, It keeps coming back to the contract for IEquatable<T> is to compare objects of type T, *not* subtypes. To guarantee this, T needs to be sealed. If alternatively, you don't agree with that, and want T to remain unsealed, you need to design the IEquatable<T> implementation to be overridable by a subtype, so you have to introduce an additional virtual member - but given system.object already has virtual object.Equals(object obj) would be there really be *any* point in implementing IEquatable<T>?
      singulars
    3. COOh, whoops. Good point, IEquatable<T> shouldn't really have to handle checking types (yes, it's icky to have to do so.) I was implementing a helper class for Equals and IEquatable a while ago, and eventually I took the chicken way out - I narrowed the purpose of IEquatable<T> from "type safe equals" to "what makes things like generic dictionaries work". No need to seal the types if you take this way out...
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload