Your code won't work because a Car
isn't a TCar
. The other way around would work: car = datcar
.
However that will probably not do what you expect as it will only make the two references car
and datcar
point to the same TCar
object.
If you want to keep the objects as separate ones but update all the properties of one object with the values of those of the properties of the other one you will have to assign them one by one. Or you can use AutoMapper which does exactly that automatically.