Errata: Item 10
p. 63.

Item 10 incorrectly implies that System.ValueType contains a static operator ==.

It doesn't. 

However, many developers do create what seems like a simple solution:

struct MyType
{
  // data members elided.
  static bool operator == ( MyType l, MyType r )
  {
    return l.Equals ( r );
  }
  // Note no override of Equals.  
}

That will cause the behavior I mentioned in the item. The reason is that ValueType.Equals() does use reflection to find the values of each field in the objects being compared.



Published Tuesday, November 15, 2005 6:54 AM by wwagner
Filed under:

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)