private void button1_Click(object sender, EventArgs e) { Order order = new Order() { CustomerName = "Test", OrderId = 98120 }; order.AddDetail("Item 1", 1, 120) .AddDetail("Item 2", 2, 220) .AddDetail("Item 3", 1, 110); textBox1.Text = $"{order.GetOrderTotalAmount().ToString("c")}\r\n"; foreach (var detail in order.FindItem("Item 1")) textBox1.Text += $"{detail.Item}: {detail.Quantity * detail.Price}\r\n"; foreach (var detail in order.Details) textBox1.Text += $"{detail.Item}: {detail.Quantity * detail.Price}\r\n"; }
private void button2_Click(object sender, EventArgs e) { // new constructor Order order = new Order() { CustomerName = "Test", OrderId = 98120 }; textBox1.Text = $"{order.ToString()}\r\n"; // new initializer Dictionary<int, string> dict = new Dictionary<int, string>() {[1] = "John",[2] = "Test",[5] = "Number 5" }; Func<string> f = ()=> { string s=""; foreach (var v in dict) s += $"{v.Key} = {dict[v.Key]}\r\n"; return s; }; textBox1.Text += f.Invoke(); order.ChangeCustomerName("Changed Name"); textBox1.Text += $"{order.ToString()}\r\n"; order = null; textBox1.Text += order?.CustomerName ?? "Null order or customer name"; }