On Jun 13, 5:42 pm, CSharper <cshar...@gmx.comwrote:
Thanks again. Do you think the following is the correct implementation
of GetHashCode?
public override int GetHashCode()
{
return this.Name.GetHashCode();
}
That's fine as long as Name isn't null.
Are you sure that you really want to only judge equality by name
though? Why not include age and gender? (Date of birth is generally
better than age, btw - it doesn't change over time.) If this is just
for the purposes of learning about Distinct() that's fine, but
otherwise you might want to implement IEqualityComparer<Person>
instead (e.g. as a NameComparer). I haven't checked whether or not
Distinct can optionally take an IEqualityComparer, but I'd be
surprised if it couldn't.
Jon