Skip to content

Instantly share code, notes, and snippets.

@NickJosevski
Created September 18, 2012 03:42
Show Gist options
  • Save NickJosevski/3741116 to your computer and use it in GitHub Desktop.
Save NickJosevski/3741116 to your computer and use it in GitHub Desktop.
IEquatable<T> Interface implementation
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