if i have reference type object, and i created two objects with the same attributes
will they have the same hash code?
sample class:
class Person
{
int id;
string name;
public Person(int pid, string pname)
{
this.id = pid;
this.name = pname;
}
}
then defining two objects:
Person p1 = new Person(1,"xxx");
Perdon p2 = new Person(1,"xxx");
//p1.GetHashCode() = p2.GetHashCode() ??
Edit:i tried this code and got differnt result but testing the thing on strings gave me the same result
that why i’m asking
You are responsible for implementing
GetHashCodeyourself. If you don’t do that, they won’t have the same hash code although they should.