I really need to compare two objects with the same class
, I have one grid with one list and need to check which one is the user changes. Here is the example
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
I tried to use
Person p1 = new Person { Name = "Jay", Age = 25 };
Person p2 = p1;
Person p3 = new Person { Name = "Jay", Age = 25 };
Console.WriteLine(p1.Equals(p2)); // True
Console.WriteLine(p1 == p2); // True
Console.WriteLine(p1.Equals(p3)); // False
Console.WriteLine(p1 == p3); // False
In resume, I don't know to compare properly two objects, use ==
or .equals
, please note that object two are copy of object one at the begin of process.