146Microsoft Visual Studio 2010: A Beginner’s Guide
namespace DebugAndTestDemo
{
class Order
{
private List<decimal> orderItems = new List<decimal>();
public decimal Total
{
get
{
decimal amount = 0;
foreach (var item in orderItems)
{
amount = amount + item;
}
return amount;
}
}
public void AddItem(decimal amount)
{
orderItems.Add(amount);
}
}
}
VB: Module1.vb
Module Module1
Sub Main()
Dim cust As Customer = New Customer() cust.Discount = 0.1D
Dim ord As Order = New Order() ord.AddItem(5D) ord.AddItem(2.5D)
cust.Order = ord
Dim discount As Decimal = cust.GetOrderDiscount()
Console.WriteLine("Customer Discount: {0}", discount) Console.ReadKey()
End Sub
End Module