Person p1 = new Person("John", 25); Person p2 = new Person("John", 25); bool result = Object.Equals(p1, p2); if (result) { Console.WriteLine("p1 and p2 are equal"); } else { Console.WriteLine("p1 and p2 are not equal"); }
Employee e1 = new Employee("John", "Doe", "developer"); Employee e2 = new Employee("John", "Smith", "developer"); bool result = Object.Equals(e1, e2); if (result) { Console.WriteLine("e1 and e2 are equal"); } else { Console.WriteLine("e1 and e2 are not equal"); }In this example, we create two Employee objects e1 and e2 with different last names. Then we compare these two objects using the Equals method. Since both objects have different values for the "LastName" property, the result of the comparison is false. Package/Library: The System.Object class is part of the .NET framework, so it is included in the System.dll library.