I have two objects of the same class:
Car oldCar = new Car()
{
Engine = "V6",
Wheels = 4
}
Car newCar = new Car()
{
Engine = "V8"
Wheels = 4
}
I want to compare the properties of the two Car
objects, and if different (like in the example), print the old and updated values, like this:
Engine: V6 -> V8
The way I'm doing this at the moment is going to be really inconvenient as I add more properties to the Car class:
if(oldCar.Engine != newCar.Engine)
Console.WriteLine(oldCar.Engine + " -> " + newCar.Engine);
How can I accomplish this in a simpler way? I don't want to manually compare every single property.