title: .Net Dictionary and the Overriding of Equals
body: <p>I know that when I create a dictionary with a custom class as key, the match when I provide a key is done through reference compare. For example:</p>
  
  <pre><code>public class SomeClass
  {
      public object SomeValue { get; set; }
  }
  
  // ....
  public static void Main()
  {
      var dict = new Dictionary&lt;SomeClass, string&gt;();
  
      var key1 = new SomeClass { SomeValue = 30 };
      dict[key1] = "30";
  
      Console.WriteLine(dict[key1]); // prints "30"
  
      var key2 = new SomeClass { SomeValue = 30 };
      Console.WriteLine(dict[key2]); // prints null 
  }
  </code></pre>
  
  <p>What happens if I override Equals (and ==) in the <code>SomeClass</code> class? Will I get "30" on the second line of the output?</p>
  
  <p>And what if I want to have a dictionary that is based on references instead of member values, but I have overridden Equals?</p>
  
  <p>Thanks!!</p>