Created
September 18, 2012 03:42
-
-
Save NickJosevski/3741116 to your computer and use it in GitHub Desktop.
IEquatable<T> Interface implementation
This file contains 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
protected bool Equals(MyClass other) | |
{ | |
return Equals(Id, other.Id) && Equals(Name, other.Name) && Equals(Desc, other.Desc); | |
} | |
public override bool Equals(object obj) | |
{ | |
if (ReferenceEquals(null, obj)) | |
{ | |
return false; | |
} | |
if (ReferenceEquals(this, obj)) | |
{ | |
return true; | |
} | |
if (obj.GetType() != this.GetType()) | |
{ | |
return false; | |
} | |
return Equals((MyClass)obj); | |
} | |
public override int GetHashCode() | |
{ | |
unchecked | |
{ | |
int hashCode = Id != null ? Id.GetHashCode() : 0; | |
hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); | |
hashCode = (hashCode * 397) ^ (Desc != null ? Desc.GetHashCode() : 0); | |
return hashCode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment