given the person class:
class person
{
public string name;
public int age;
}
say, i override the class person`s GetHashCode method:
public override int GetHashCode()
{
unchecked
{
hashCode = 17;
// ...some code here...
}
return hashCode;
}
and based on msdn`s instruction, i also need to override the Equality, so i did this:
public override bool Equals(object obj)
{
// ...something like:
return this.name == (person)obj.name && this.age ==(person)obj.age;
}
hey, wait, sine i can get the hashcode of the person instance, why not just using hashcode in Equals? like:
public override bool Equals(object obj)
{
return this.GetHashCode() == (person)obj.GetHashCode();
}
i googled and found that most Equals() examples are similar with my previous edition of Equals(), so, am i misunderstood something?
any help will appreciated, thx.