I have a class that contains the following two properties:
public int Id { get; private set; }
public T[] Values { get; private set; }
I have made it IEquatable<T>
and overriden the object.Equals
like this:
public override bool Equals(object obj)
{
return Equals(obj as SimpleTableRow<T>);
}
public bool Equals(SimpleTableRow<T> other)
{
// Check for null
if(ReferenceEquals(other, null))
return false;
// Check for same reference
if(ReferenceEquals(this, other))
return true;
// Check for same Id and same Values
return Id == other.Id && Values.SequenceEqual(other.Values);
}
When having override object.Equals
I must also override GetHashCode
of course. But what do I put in it? How do I create a hashcode out of a generic array? And how do i combine it with the Id
integer?
public override int GetHashCode()
{
return // What?
}