static void Main(string[] args) { var cart1 = new ShoppingCart(); var banana = new ShoppingCartItem() { Name = "Bananas", Price = 2.25m }; var beanie = new ShoppingCartItem() { Name = "Beanie Baby", Price = 12.34m }; var ps3 = new ShoppingCartItem() { Name = "PS3", Price = 150.99m }; banana.Id = cart1.AddItem(banana); beanie.Id = cart1.AddItem(beanie); ps3.Id = cart1.AddItem(ps3); cart1.RemoveItem(3); cart1.ListItems(); Debug.Assert(cart1.AddItem(new ShoppingCartItem { Name = "dlk", Price = 3.2m }) == 3, "This is not the 3rd index"); Debug.Assert(cart1.RemoveItem(1) == true, "There is no cart1 item 1"); Debug.Assert(cart1.ListItems() == 3, "There aren't 3 items here"); Console.ReadLine(); }
public int AddItem(ShoppingCartItem item) { CartList.Add(item); return CartList.IndexOf(item); }
public int AddItem(string name, decimal price) { ShoppingCartItem item = new ShoppingCartItem(name, price, newItemNum++); cart.Add(item); return item.Id; }
public int AddItem(ShoppingCartItem item) { CartList.Add(item); return(CartList.IndexOf(item)); }
//public static int AddItem(string name, int id, decimal price) public static int AddItem(ShoppingCartItem item) { return item.Id; }
//public static int AddItem(string name, int id, decimal price) public static int AddItem(ShoppingCartItem item) { return(item.Id); }