为什么两个对象的哈希码不相同,即使它们具有相似的值。在不读取每个属性并检查其他属性的情况下找到对象之间值相等的另一种最佳方法是什么?
Person person = new Person();
person.Name = "X";
person.Age = 25;
person.Zip = 600056;
person.Sex = 'M';
Person person1 = new Person();
person1.Name = "X";
person1.Age = 25;
person1.Zip = 600056;
person1.Sex = 'M';
int hashCode1 = person1.Name.GetHashCode();
int hashCode = person.Name.GetHashCode();
// hashCode1 and hashCode values are same.
if (person.GetHashCode() == person1.GetHashCode())
{
// Condition is not satisfied
}