static void Main(string[] args) { Invoice i1 = new Invoice(); for (int i = 0; i < 2; i++) { i1.DetailLines.Add(new InvoiceDetailLine(i + 1)); } i1.PrintInvoice(); Invoice i2 = new Invoice(); for (int i = 0; i < 2; i++) { i2.DetailLines.Add(new InvoiceDetailLine(i + 1)); } Invoice summaryInvoice = i1 + i2; Console.WriteLine("*** Summary Invoice for Invoices 1 & 2 ***"); summaryInvoice.PrintInvoice(); Console.ReadLine(); }
public static Invoice operator +(Invoice invoice1, Invoice invoice2) { Invoice returnInvoice = new Invoice(); foreach (InvoiceDetailLine detailLine in invoice1.DetailLines) { returnInvoice.DetailLines.Add(detailLine); } foreach (InvoiceDetailLine detailLine in invoice2.DetailLines) { returnInvoice.DetailLines.Add(detailLine); } return returnInvoice; }