//remove from list public void removeFromList(IceCream iceCream) { for (int i = 0; i < iceCreamList.Count; i++) { if (iceCreamList[i].getname() == iceCream.getname()) { if (iceCreamList[i].getamount() - iceCream.getamount() <= 0) { iceCreamList.RemoveAt(i); return; } else { int oldAmmount = iceCreamList[i].getamount(); iceCreamList[i].setAmount(oldAmmount - iceCream.getamount()); return; } } } }
//add to list public void addToList(IceCream iceCream) { bool iceCreaFound = false; if (iceCreamList.Count > 0) { for (int i = 0; i < iceCreamList.Count; i++) { if (iceCreamList[i].getname() == iceCream.getname()) { int newAmmount = iceCreamList[i].getamount() + iceCream.getamount(); iceCreamList[i].setAmount(newAmmount); iceCreaFound = true; } } } if (!iceCreaFound) { iceCreamList.Add(iceCream); } }