コード例 #1
0
 //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;
             }
         }
     }
 }
コード例 #2
0
        //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);
            }
        }