title: how to implement override of GetHashCode() with logic of overriden Equals()
body: <p>I have some classes as below, i have implemented the <code>Equals(Object)</code> method for almost all of them. But i don't know how to write  <code>GetHashCode()</code> . As far I used these data types as value type in a <code>Dictionary</code> Collection, i think i should override <code>GetHashCode()</code>.</p>
  
  <p>1.I don't know how to implement <code>GetHashCode()</code> with logic of <code>Equals(Object)</code>.</p>
  
  <p>2.There are some derived classes, if i override <code>GetHashCode()</code> and <code>Equals(Object)</code> for base class ( <code>Param</code> ), is it still necessary to override it for childs?</p>
  
  <pre><code>class Param
  {
      ...
      public Int16 id { get; set; }
      public String name { get; set; }
      ...
      public override bool  Equals(object obj)
      {
          if ( obj is Param){
              Param p = (Param)(obj);
              if (id &gt; 0 &amp;&amp; p.id &gt; 0)
                  return (id == p.id);
              else if (name != String.Empty &amp;&amp; p.name != String.Empty)
                  return (name.equals(p.name));
              else
                  return object.ReferenceEquals(this, obj);
          }
          return false;
      }
  }  
  class Item
  {
      public int it_code { get; set; }
      public Dictionary&lt;String, Param&gt; paramAr { get; set; }
      ...
      public override bool Equals(Object obj)
      {
          Item im = new Item();
          if (obj is Item)
              im = (Item)obj;
          else 
              return false;
  
          if (this.it_code != String.Empty &amp;&amp; im.it_code != String.Empty)
              if (this.it_code.Equals(im.it_code)) 
                  return true;
  
          bool reParams = true;
          foreach ( KeyValuePair&lt;String,Param&gt; kvp in paramAr ){
              if (kvp.Value != im.paramAr[kvp.Key]) {
                  reParams = false;
                  break;
              }
          }
          return reParams;
      }
  }
  class Order
  {
  
      public String or_code { get; set; }
      public List &lt;Item&gt; items { get; set; }
      ...
      public override bool Equals( Object obj ){
          Order o = new Order();
          if (obj is Order)
              o = (Order)obj;
          else
              return false;
  
          if (this.or_code != String.Empty &amp;&amp; o.or_code != String.Empty)
              if (this.or_code.Equals(o.or_code))
                  return true;
          bool flag = true;
          foreach( Item i in  items){
              if (!o.items.Contains(i)) { 
                  flag = false;
                  break;
              }
          }
          return flag;
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  i get this warning:</p>
  
  <blockquote>
    <p>Warning   : 'Item' overrides Object.Equals(object o) but does not
    override Object.GetHashCode()</p>
  </blockquote>