コード例 #1
0
        private static void ChooseFood(List <ClassFood> groceries, Persons client)
        {
            Console.WriteLine("What do you want to buy?");
            string    foodName   = Console.ReadLine();
            ClassFood chosenFood = groceries.FirstOrDefault(x => x.Name == foodName);

            if (chosenFood == null)
            {
                Console.WriteLine("Excuse me, we don't have " + foodName + "in our shop");
            }
            else
            {
                Console.WriteLine("How much?");
                string amount = Console.ReadLine();
                int    a;
                bool   success = int.TryParse(amount, out a);
                while (!success)
                {
                    Console.WriteLine("Excuse me, amount should be integer value: ");
                    amount  = Console.ReadLine();
                    success = int.TryParse(amount, out a);
                }
                client.ShoppingCart.AddToCart(chosenFood, a);
            }
            Console.WriteLine("Anything else? Y/N");
        }
コード例 #2
0
 public void AddToCart(ClassFood food, int amount)
 {
     Items.Add(food);
     Amounts.Add(amount);
 }