title: Why do we need GetHashCode() function in the Object Model Project?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/371328/why-is-it-important-to-override-gethashcode-when-equals-method-is-overriden-in-c">Why is it important to override GetHashCode when Equals method is overriden in C#?</a>  </p>
  </blockquote>
  
  
  
  <p>I was looking into the following class in my <code>Object Model</code> and could not understand the significance of adding <code>GetHashCode()</code> in the <code>Class</code>.</p>
  
  <h2>Sample Class</h2>
  
  <pre><code>public class SampleClass
  {
  
      public int ID { get; set; }
      public String Name { get; set; }
      public String SSN_Number { get; set; }
  
      public override bool Equals(Object obj)
      {
          if (obj == null || GetType() != obj.GetType())
              return false;
  
          SampleClass cls = (SampleClass)obj;
          return (ID == cls.ID) &amp;&amp;
                 (Name == cls.Name) &amp;&amp;
                 (SSN_Number == cls.SSN_Number);
      }
  
      public override int GetHashCode()
      {
          return ID.GetHashCode() ^ Name.GetHashCode() ^ SSN_Number.GetHashCode();
      }
  }
  </code></pre>
  
  <p>Suppose I have a list of <code>Sample Class</code> Object and I want to get a specific index. Then <code>Equals()</code> can help me to get that record. Why should I use <code>GetHashCode()</code> ?</p>