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

            if (chosenFood == null)
            {
                Console.WriteLine("Sorry, no food " + foodName + " in our candy shop");
            }
            else
            {
                Console.WriteLine("How much do you want? ");
                string amount = Console.ReadLine();
                int    a;
                bool   success = int.TryParse(amount, out a); //
                while (!success)
                {
                    Console.WriteLine("Sorry, 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");
            }
            Console.WriteLine("Anything else? Y/N");
        }
示例#2
0
 public void AddtoCart(Class_food food, int amount)
 {
     Items.Add(food);
     Amounts.Add(amount);
 }