I have a class
public class Car()
{
public string Name;
public string Model;
}
And i have a property
List<Car> CarsA = new List<Car>();
CarsA.Add(new Car(){Name = "Verna",Model="Hyundai"});
CarsA.Add(new Car(){Name = "X1",Model="Bmw"});
and i have another property
List<Car> CarsB = new List<Car>();
Now i want to add clone/copy all the entries from CarsA to CarsB without taking CarsA properties current instances
(i.e. i want to create new object for each entry and add it).
Something like
foreach(var car in CarsA)
{
Car newCar =new Car();
newCar.Name = car.Name;
newCar.Model = car.Model;
CarsB.Add(newCar);
}
What if i don't want to implement ICloneable and i don't have a copy contructor?