title: Correct way to override Equals() and GetHashCode()
body: <p>I have never really done this before so i was hoping that someone could show me the correct what of implementing a override of Except() and GetHashCode() for my class. </p>
  
  <p>I'm trying to modify the class so that i can use the LINQ Except() method.</p>
  
  <pre><code>public class RecommendationDTO{public Guid RecommendationId { get; set; }
  public Guid ProfileId { get; set; }
  public Guid ReferenceId { get; set; }
  public int TypeId { get; set; }
  public IList&lt;TagDTO&gt; Tags { get; set; }
  public DateTime CreatedOn { get; set; }
  public DateTime? ModifiedOn { get; set; }
  public bool IsActive { get; set; }
  public object ReferencedObject { get; set; }
  public bool IsSystemRecommendation { get; set; }
  public int VisibilityScore { get; set; }
  
  public RecommendationDTO()
  {
  }
  
  public RecommendationDTO(Guid recommendationid,
                              Guid profileid,
                              Guid referenceid,
                              int typeid,
                              IList&lt;TagDTO&gt; tags,
                              DateTime createdon,
                              DateTime modifiedon, 
                              bool isactive,
                              object referencedobject)
  {
      RecommendationId = recommendationid;
      ProfileId = profileid;
      ReferenceId = referenceid;
      TypeId = typeid;
      Tags = tags;
      CreatedOn = createdon;
      ModifiedOn = modifiedon;
      ReferencedObject = referencedobject;
      IsActive = isactive;
  }
  
  public override bool Equals(System.Object obj)
  {
      // If parameter is null return false.
      if (obj == null)
      {
          return false;
      }
  
      // If parameter cannot be cast to Point return false.
      RecommendationDTO p = obj as RecommendationDTO;
      if ((System.Object)p == null)
      {
          return false;
      }
  
      // Return true if the fields match:
      return (ReferenceId == p.ReferenceId);// &amp;&amp; (y == p.y);
  }
  
  public bool Equals(RecommendationDTO p)
  {
      // If parameter is null return false:
      if ((object)p == null)
      {
          return false;
      }
  
      // Return true if the fields match:
      return (ReferenceId == p.ReferenceId);// &amp;&amp; (y == p.y);
  }
  
  //public override int GetHashCode()
  //{
  //    return ReferenceId;// ^ y;
  //}}
  </code></pre>
  
  <p>I have taken a look at <a href="http://msdn.microsoft.com/en-us/library/ms173147.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms173147.aspx</a> but i was hoping someone could show me within my own example.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thank you</p>