title: Dictionary.ContainsKey() - How does it work?
body: <p>I've read the MSDN documentation on how <code>Dictionary.ContainsKey()</code> works, but I was wondering how it actually makes the equality comparison? Basically, I have a dictionary keyed to a reference type* and I want the <code>ContainsKey()</code> method to check a certain property of that reference type as its basis for determining if the key exists or not. For example, if I had a <code>Dictionary(MyObject, int)</code> and <code>MyObject</code> has a public property (of <code>int</code>) called "TypeID", could I get <code>ContainsKey(MyObject myObject)</code> to check to see if one of the keys has a <code>TypeID</code> that is equal to <code>myObject</code>? Could I just overload the <code>==</code> operator?</p>
  
  <ul>
  <li>The reference type is an object called "Duration" which holds a value (<code>double Length</code>); "Duration" is a base type used in my music program to denote how long a particular sound lasts. I derive classes from it which incorporate more sophisticated timing concepts, like Western musical time signatures, but want all of them to be comparable in terms of their length.</li>
  </ul>
  
  <p>EDIT: As suggested, I implemented IEquitable on my object like so:</p>
  
  <pre><code> public class Duration : IEquatable&lt;Duration&gt;
   {
      protected double _length;
  
      /// &lt;summary&gt;
      /// Gets or Sets the duration in Miliseconds.
      /// &lt;/summary&gt;
      public virtual double Length
  {
          get
          {
              return _length;
          }
          set
          {
              _length = value;
          }
      }
  
  // removed all the other code that as it was irrelevant
  
      public override bool Equals(object obj)
      {
          Duration otherDuration = (Duration)obj;
          if (otherDuration._length == _length)
          {
              return true;
          }
          else
          {
              return false
          }
      }
  
  }
  </code></pre>
  
  <p>Is this all I need to do?</p>