public static void Main(string[] args) { Payment fp = new Payment("Himikal", 2m); Payment sp = new Payment("tefter", 3m); List<Payment> firstPayments = new List<Payment>(); firstPayments.Add(fp); List<Payment> secondPayments = new List<Payment>(); secondPayments.Add(sp); Customer first = new Customer("Pavel", "Veselinov", "Ilchev", "8206211125", "Varna", "577160", "*****@*****.**", firstPayments, CustomerType.Diamond); Customer second = new Customer("Natalia", "Krasimirova", "Nikolova", "8804151312", "Varna", "560250", "*****@*****.**", secondPayments, CustomerType.Golden); Customer copy = first.Clone(); copy.Payments.Add(new Payment("test", 4.5m)); Console.WriteLine(first); Console.WriteLine(copy); Console.WriteLine(first.CompareTo(second)); Console.ReadKey(true); }
public Customer Clone() { List<Payment> paymentsCopy = new List<Payment>(); foreach (var payment in this.Payments) { var productNameCopy = payment.ProductName; var priceCopy = payment.Price; var paymentCopy = new Payment(productNameCopy, priceCopy); paymentsCopy.Add(paymentCopy); } Customer copy = new Customer(this.FirstName, this.MiddleName, this.LastName, this.ID, this.PermanentAddress, this.MobilePhone, this.Email, paymentsCopy, this.Type); return copy; }