Skip to content

Instantly share code, notes, and snippets.

@jackinf
Created June 26, 2014 07:21
Show Gist options
  • Save jackinf/7b39ac71c720bee193cc to your computer and use it in GitHub Desktop.
Save jackinf/7b39ac71c720bee193cc to your computer and use it in GitHub Desktop.
implement IEquatable<T> for comparing objects
public class Author : IEquatable<Author>
{
public string FirstName { get; set; }
public string LastName { get; set; }
public bool Equals(Author other)
{
if (FirstName == other.FirstName && LastName == other.LastName)
return true;
return false;
}
public override int GetHashCode()
{
int hashFirstName = FirstName == null ? 0 : FirstName.GetHashCode();
int hashLastName = LastName == null ? 0 : LastName.GetHashCode();
return hashFirstName ^ hashLastName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment