Created
June 26, 2014 07:21
-
-
Save jackinf/7b39ac71c720bee193cc to your computer and use it in GitHub Desktop.
implement IEquatable<T> for comparing objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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