title: C# GetHashCode() High Performance Hashing Algorithm
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode">What is the best algorithm for an overridden System.Object.GetHashCode?</a>  </p>
  </blockquote>
  
  
  
  <p>This is known to us that if we override the <code>Equals</code> method of <code>Object</code> in our custom types, we should also override and provide an implementation of <code>GetHashCode</code> method to support generating unique hash codes for use in support of <code>Hashtable</code> and <code>Dictionary</code> collection classes and may be other classes.</p>
  
  <p>This mandates our implementation of the hashing algorithm used inside our <code>overriden</code> <code>GetHashCode</code> method is optimal and accurate i.e. it generates a unique hash of the type and also does that as quickly as possible to improve performance of application that uses our type.</p>
  
  <p>My question is to <strong><em>which hashing algorithms</em></strong> are accurate and give optimal performance when used in <code>GetHashCode</code> implementation? Or, should we only use the base type's <code>GetHashCode</code> implementation? I would like to know this answer for both <code>value types</code> and <code>reference types</code>..</p>
  
  <p>Edit: Here's an example of a class below on why I would need to override <code>Equals</code>:</p>
  
  <pre><code>public class Laptop : LaptopBase
  {
      public readonly string Make;
      public readonly string ProcessorArch;
      public readonly int MemorySupported;
      public readonly int HardDiskGBSupported;
      public readonly Color ColorName;
  
      public Laptop(make, procArch, memorySupp, hdGB, color)
      {
          Make = make;
          ProcessorArch = procArch;
          MemorySupported = memorySupp;
          HardDiskGBSupported = hdGB;
          ColorName = color;
      }
  }
  </code></pre>
  
  <p>Now, I want to return true for 2 Laptop instances that have all the above defined fields matching with each other so that requires to override the <code>Equals</code> and <code>GetHashCode</code> method and also another requirement as you can see is that this is a derived class and may be re-used further and support a number of methods; and thus, cannot be made a value type (struct). I tried with 2 instances of above type with all matching instance fields and if I use the base implementation of <code>Equals</code> - it returns <code>false</code> where I want it to be <code>true</code>..
  <strong>How would I support such a scenario?</strong></p>