PART II
C h a p t e r 2 4 :
C o l l e c t i o n s , E n u m e r a t o r s , a n d I t e r a t o r s
801
cost = c;
onhand = h;
}
public override string ToString() {
return
String.Format("{0,-10}Cost: {1,6:C} On hand: {2}",
name, cost, onhand);
}
}
class TypeSafeInventoryList {
static void Main() {
List inv = new List();
// Add elements to the list.
inv.Add(new Inventory("Pliers", 5.95, 3));
inv.Add(new Inventory("Wrenches", 8.29, 2));
inv.Add(new Inventory("Hammers", 3.50, 4));
inv.Add(new Inventory("Drills", 19.88, 8));
Console.WriteLine("Inventory list:");
foreach(Inventory i in inv) {
Console.WriteLine(" " + i);
}
}
}
In this version, notice the only real difference is the passing of the type
Do'stlaringiz bilan baham: |