public Product clone() { Train clone = (Train)this.MemberwiseClone(); clone.wagons = new List <string>(wagons); clone.locomotive = (Locomotive)locomotive.clone(); return(clone); }
public static void Main(string[] args) { Locomotive oldLocomotive = new Locomotive(15); Product newLocomotive = oldLocomotive.clone(); Train longTrain = new Train(oldLocomotive); longTrain.add_wagon("Passenger"); Product shortTrain = longTrain.clone(); longTrain.add_wagon("Freight"); oldLocomotive.set_price(7); System.Console.WriteLine(newLocomotive.get_cost() - oldLocomotive.get_cost()); System.Console.WriteLine(shortTrain.get_cost() - longTrain.get_cost()); }